I have a machine that has eth0 and eth1, and now I want to create an eth2 and assign it some IP address.

What's the command for doing this?


On Linux machines, eth0 and eth1 correspond to real network ports. To add an eth2, you'll need to add another NIC, either by adding an internal PCI(e) network card, or by adding a USB network adapter. See Redhat network interface configuration.

If all you want is another IP address, you can create an ethernet alias on one of your existing adapters. An alias is like a virtual network card -- it lets you assign another IP address to an existing port. Let's assume your eth0 has the IP address 192.168.1.5.

To do this once, run (as root) ifconfig eth0:0 192.168.1.6 up. (Use eth0:1 for a second alias on eth0, eth0:2 for a third, or eth1:0 to alias eth1 instead of eth0.) This configuration will be lost at reboot.

To configure it permanently, add it to a configuration script. Make a copy of /etc/sysconfig/network-scripts/ifcfg-eth0 to the file ifcfg-eth0:0 in the same directory. Change the new file so it looks like this:

DEVICE=eth0:0
IPADDR=192.168.1.6
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
NAME=eth0:0

The remove or comment out any GATEWAY lines in both files, and add the GATEWAY line to your /etc/sysconfig/network file. Then you can start the new alias with ifup eth0:0 or restart networking entirely with service network restart.


From the way the question is asked it is not clear what is meant when it is said that the machine only has eth0 and eth1. Other answerers have made an assumption that there are only two NIC cards, but it is also possible that the third NIC is already installed on the compute, but has not been "brought up" (or has been explicitly shut down).

Let us assume that you are sure that you have 3 NIC cards, but somehow when you do ifconfig your output is something along the lines of:

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:439793 errors:0 dropped:0 overruns:0 frame:0
          TX packets:439793 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:412415058 (412.4 MB)  TX bytes:412415058 (412.4 MB)

eth0      Link encap:Ethernet  HWaddr [mac address]
          [...]

eth1      Link encap:Ethernet  HWaddr [mac address]
          [...]

There seems to be a contradiction, you have 3 NIC cards, but only two ports. That is because ifconfig only shows those ports which are "up". So the only thing that you need to do is to run the command:

ifconfig eth2 up

Keep in mind that it needs to be run as root, do that as is required in your distribution.

You can combine setting the IP address with "bringing the port up":

ifconfig eth2 192.168.222.2 netmask 255.255.255.0 up

The "up" should be after other things on this line, but it will still work.