开发者

Binding to a specific ip address when using the PHP mysql_connect function

开发者 https://www.devze.com 2023-04-10 08:13 出处:网络
I have a Cent OS setup running a pretty standard LAMP stack and I have two publicly available IP addresses (eth0 and eth0:1).

I have a Cent OS setup running a pretty standard LAMP stack and I have two publicly available IP addresses (eth0 and eth0:1).

I want to use the second IP address (eth0:1) when connecting out to a remotely开发者_StackOverflow社区 hosted MySQL database. How can I go about that?

Thanks!


If you have root access, you can do SNAT with iptables to use a specific source IP for this particular destination:

iptables -t nat -A POSTROUTING -o eth0 -d <mysql_server_ip> -j SNAT --to-source <source_ip>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号