Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

just wondering how it is actually possible to have a server with multiple IPs


I have a python script, and would like to be able to use different IP addresses for different requests.

Is this actually possible?


EDIT:

I'm running CentOS 5 and have 3 IP Addresses asscociated with the machine

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Is this a question about Python (a) or having multiple IPs on the server (b)?

If (a) then yes, you just have to bind the socket to a particular IP address that you want to use. For example:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(YOUR_IP_ADDRESS)
s.connect((REMOTE_HOST, REMOTE_PORT))

Anticipating a question about the urlopen, pls look at my comment on StackOverflow

If (b) then you just configure additional IPs in the /etc/sysconfig/network-scripts/ifcfg-eth0:X /where X is a virtual interface ID, 0, 1, 2, etc) (assuming that all IPs are on that interface. If they are not then provision them in ifcfg-eth1, etc)

Once the configuration is in place, restart your network: service network restart

share|improve this answer

Sure. Run ifconfig on the server and it will show you all the network attachments on the server and their currently bound IP addresses.

To add an additional IP to one of the network adapters, edit it into the network configuration file for that adapter. The files are explained here: http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-networkscripts-files.html

share|improve this answer

On a development machine this is usually chosen to be localhost.

On a production machine you probably want to explicitly set the IP Address.

Sometimes you want the application to be available on all IP Addresses, in which case you could use 0.0.0.0, the special IP address that means (in this case) "All IP addresses" belonging to this host.

This might not always be what you want as one IP address could be for maintenance access only and for example you might not want your application to be accessible on the network used for, say, backups.

[Can someone confirm this for sure? I can't find the 0.0.0.0 behaviour in the Python documentation or test it easily right now]

share|improve this answer
    
Yes 0.0.0.0 == listen on all available addresses. When binding, socket.bind(('0.0.0.0', port)). –  McJeff May 3 '10 at 4:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.