Feb
27
How to have two IPs on one interface
Filed Under Command line, Linux
Recently I got into problem to assign 2 IPs on one physical NIC.
There was nothing mentioned in official documentation so I did some research and find the solution.
It is really simple if you are not afraid from command line and VI editor. Unfortunately I did not find a GUI.
Here it is:
- Go to command prompt
- Be sure that you are root. Otherwise type su – to become.
- Type – cd /etc/sysconfig/network-scripts/
- Then type ls to see the contents – you should have file ifcfg-eth0 if you have just one interface otherwise if you have multiple interfaces there you’ll find other files like ifcfg-eth1…n.
- Then we will copy the file to different name – cp ifcfg-eth0 ifcfg-eth0:0
- Next step is to edit newly created file and put the IP we needed.
- If needed repeat steps 5 and 6 with different numbers after”:” (1,2,…) to add additional addresses.
- If you issue ifconfig you will not see newly created interface, because it is no activated – you need to restart network /etc/init.d/network restart will do it for you.
- That’s it.
Comments are welcome.
Comments
One Response to “How to have two IPs on one interface”
Leave a Reply
You must be logged in to post a comment.
One thing is missing in your steps. In step 5, you need to change the IP, but also change the “DEVICE” field to “eth0:0”. Without this extra step, the ifcfg-eth0:0 file will override the network settings of the ifcfg-eth0 file when going up.
I think the official documentation is in “sysconfig.txt”, but it isn’t documented very well.