1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

How can I bind to specific IP Address for outbound PHP/MySQL connection (linux)?




Have multiple IP addresses, using aliases, for instance:

eth0 192.168.0.1
eth0:0 192.168.0.101
eth0:1 192.168.0.102 <- would like to use
eth0:2 192.168.0.103

Would like to bind the outbound ip address, there is no mysql server on this box. For security purposes, I must connect to the remote server using a specific unchangeable ip address. Nor can I change the primary IP address on this box.

debian box, with root access.


2 Responses to “How can I bind to specific IP Address for outbound PHP/MySQL connection (linux)?”

  • Harold L says:

    In your IP aliasing setup, I’d swap the IP addresses for eth0 and eth0:1 so that the default IP address for outgoing connections is 192.168.0.102.

    Your machine will still accept incoming connections on all of the IPs.

    If you have to do this for several of the virtual hosts on your Linux machine, look into user-mode Linux (see link in the sources). Think light-weight virtual machines, each with their own IP address and Apache/PHP setup.

    I think those are the best options – I don’t see a way in the sockets API (e.g. man(2) connect) to specify your return IP address. And even if there were, you’d have to patch the PHP or MySQL driver code to add a configuration option for telling it what IP address to connect from. It is possible, based on the IP spec, of course – but people don’t usually need to do this, so it isn’t easy to configure.

    http://www.faqs.org/docs/Linux-mini/IP-Alias.html
    http://user-mode-linux.sourceforge.net/

    Report this comment

  • Website Managers says:

    When you install MySQL a file named my.cnf is created in /etc. Inside that file is a line that allows you to bind MySQL to an IP address. After making your changes, remember to restart MySQL, usually in /etc/rc.d/init.d/mysqld

    http://www.google.com/search?q=my.cnf+bind-address

    Report this comment

Leave a Reply

Spam Protection by WP-SpamFree

TigerDirect