There are times when you may want to add a second or multiple IP addresses to your linux system. It’s fairly straightforward to add a sub-interface to your current configuration. In fact, it’s just as easy to add ten sub-interfaces as it is one.
Start by opening a console with root permissions.
Next we edit the interfaces configuration file.
# nano /etc/network/interfaces
Within the interfaces file, you should see a section that contains IP information for your current network interface cards.
My primary interface in this example is “eth0″. If I want to add another ip address to that interface I would start by defining it. For example add a line like the following and modify it to match your setup.
Notice that it is named the same as my original “eth0″ but also has “:1″ appended to it.
Below that line add the following line. Again, modifying the interface name to match your configuration.
iface eth0:1 inet static
Next you need to add the IP addressing information. I’ve used the following.
Press “ctrl-x” to exit nano editor. Press “y” to save modifications.
Accept the default save path.
Next, we need to restart the network service.
# /etc/init.d/networking restart
Be alert for any errors when restarting the network. This will indicate a possible typo in the configuration if you get an error.
Let’s view the new sub-interface we created.
# ifconfig eth0:1
All the settings seem to have taken effect…
Next we’ll ping the interface to test it.
# ping 172.17.2.10
Successful ping requests are always a good sign. At this point you may want to try to ping another IP address on the same subnet as your new interface. I’ll leave that part in your capable hands.
We’re all done here, so I’ll log off as root.