How to Assign Multiple IPs to a Single Network Interface in Linux

The concept of creating or configuring multiple IP addresses on a single network interface is called IP aliasing, which is very useful for setting up multiple virtual sites on a web server using one single network interface with different IP addresses on a single subnet network.

The main advantage of using this IP aliasing is that you don’t need to have a physical adapter attached to each IP. Instead, you can create multiple or many virtual interfaces (aliases) for a single physical card.

The instructions given here apply to all RHEL-based distributions such as Fedora, CentOS, Rocky, and Alma Linux. Creating multiple interfaces and assigning IP addresses to them manually is a daunting task.

Here, we’ll see how to assign IP addresses by defining a set of IP ranges. We’ll also understand how to create a virtual interface and assign a different range of IP addresses to it all at once.

In this article, we used LAN IPs, so replace those with the ones you will be using.

How to Create Multiple IP Addresses to Single Network Interface

Here, I have an interface named ‘ifcfg-eth0‘, which is the default network interface card for the ethernet device. If you’ve connected a second ethernet device, it will appear as ‘ifcfg-eth1‘, and so on for each additional device.

These network files for the devices are found in the ‘/etc/sysconfig/network-scripts/‘ directory and you can list all devices using the following ls command.

ls -l /etc/sysconfig/network-scripts/

Sample Output:

ifcfg-eth0   ifdown-isdn    ifup-aliases  ifup-plusb     init.ipv6-global
ifcfg-lo     ifdown-post    ifup-bnep     ifup-post      net.hotplug
ifdown       ifdown-ppp     ifup-eth      ifup-ppp       network-functions
ifdown-bnep  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6
ifdown-eth   ifdown-sit     ifup-ipv6     ifup-sit
ifdown-ippp  ifdown-tunnel  ifup-isdn     ifup-tunnel
ifdown-ipv6  ifup           ifup-plip     ifup-wireless

Let’s assume that we want to create three additional virtual interfaces to bind three IP addresses (172.16.16.126, 172.16.16.127, and 172.16.16.128) to the NIC.

So, we need to create three additional alias files, while “ifcfg-eth0” keeps the same primary IP address. This is how we move forward to set up three aliases to bind the following IP addresses.

Adapter            IP Address                Type
-------------------------------------------------
eth0              172.16.16.125            Primary
eth0:0            172.16.16.126            Alias 1
eth0:1            172.16.16.127            Alias 2
eth0:2            172.16.16.128            Alias 3

Where ":X" represents the device (interface) number for creating aliases for interface eth0. For each alias, you must assign a number sequentially.

For example, we copy existing parameters from the interface “ifcfg-eth0” to virtual interfaces named ifcfg-eth0:0, ifcfg-eth0:1, and ifcfg-eth0:2.

Navigate to the network directory and create the files as shown below.

cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2

Open a file “ifcfg-eth0” and view the contents.

vi ifcfg-eth0

Sample Output:

DEVICE="eth0"
BOOTPROTO=static
ONBOOT=yes
TYPE="Ethernet"
IPADDR=172.16.16.125
NETMASK=255.255.255.224
GATEWAY=172.16.16.100
HWADDR=00:0C:29:28:FD:4C

Here, we only need two parameters (DEVICE and IPADDR). So, open each file with your favorite editor, rename the DEVICE name to its corresponding alias, and change the IPADDR address.

For example, open files ‘ifcfg-eth0:0‘, ‘ifcfg-eth0:1‘, and ‘ifcfg-eth0:2‘ using the VI editor and update both parameters.

Finally, it will look similar to the example below.

ifcfg-eth0:0
DEVICE="eth0:0"
BOOTPROTO=static
ONBOOT=yes
TYPE="Ethernet"
IPADDR=172.16.16.126
NETMASK=255.255.255.224
GATEWAY=172.16.16.100
HWADDR=00:0C:29:28:FD:4C
ifcfg-eth0:1
DEVICE="eth0:1"
BOOTPROTO=static
ONBOOT=yes
TYPE="Ethernet"
IPADDR=172.16.16.127
NETMASK=255.255.255.224
GATEWAY=172.16.16.100
HWADDR=00:0C:29:28:FD:4C
ifcfg-eth0:2
DEVICE="eth0:2"
BOOTPROTO=static
ONBOOT=yes
TYPE="Ethernet"
IPADDR=172.16.16.128
NETMASK=255.255.255.224
GATEWAY=172.16.16.100
HWADDR=00:0C:29:28:FD:4C

Once, you’ve made all changes, save all your changes and restart/start the network service for the changes to reflect.

systemctl restart network

To verify all the aliases (virtual interface) are up and running, you can use “ifconfig” or “ip” command.

ifconfig

Sample Output:

eth0      Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.125  Bcast:172.16.16.100  Mask:255.255.255.224
          inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:237 errors:0 dropped:0 overruns:0 frame:0
          TX packets:198 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:25429 (24.8 KiB)  TX bytes:26910 (26.2 KiB)
          Interrupt:18 Base address:0x2000

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.126  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.127  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.128  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

Now try to ping each of them from a different machine. If everything is set up correctly, you will receive a ping response from each of them.

ping 172.16.16.126
ping 172.16.16.127
ping 172.16.16.128

Sample Output:

ping 172.16.16.126
PING 172.16.16.126 (172.16.16.126) 56(84) bytes of data.
64 bytes from 172.16.16.126: icmp_seq=1 ttl=64 time=1.33 ms
64 bytes from 172.16.16.126: icmp_seq=2 ttl=64 time=0.165 ms
64 bytes from 172.16.16.126: icmp_seq=3 ttl=64 time=0.159 ms

ping 172.16.16.127
PING 172.16.16.127 (172.16.16.127) 56(84) bytes of data.
64 bytes from 172.16.16.127: icmp_seq=1 ttl=64 time=1.33 ms
64 bytes from 172.16.16.127: icmp_seq=2 ttl=64 time=0.165 ms
64 bytes from 172.16.16.127: icmp_seq=3 ttl=64 time=0.159 ms

ping 172.16.16.128
PING 172.16.16.128 (172.16.16.128) 56(84) bytes of data.
64 bytes from 172.16.16.128: icmp_seq=1 ttl=64 time=1.33 ms
64 bytes from 172.16.16.128: icmp_seq=2 ttl=64 time=0.165 ms
64 bytes from 172.16.16.128: icmp_seq=3 ttl=64 time=0.159 ms

It appears that everything is working smoothly. With these new IPs, you can set up virtual sites in Apache, FTP accounts, and many other things.

Assign Multiple IP Addresses Range

If you would like to create a range of multiple IP addresses to a particular interface called “ifcfg-eth0“, we use “ifcfg-eth0-range0” and copy the contents of ifcfg-eth0 on it as shown below.

cd /etc/sysconfig/network-scripts/
cp -p ifcfg-eth0 ifcfg-eth0-range0

Now open the “ifcfg-eth0-range0” file.

vi ifcfg-eth0-range0

and add “IPADDR_START” and “IPADDR_END” IP address ranges as shown below.

#DEVICE="eth0"
#BOOTPROTO=none
#NM_CONTROLLED="yes"
#ONBOOT=yes
TYPE="Ethernet"
IPADDR_START=172.16.16.126
IPADDR_END=172.16.16.130
IPV6INIT=no
#GATEWAY=172.16.16.100

Save it and restart/start the network service

systemctl restart network

Verify that virtual interfaces are created with IP Addresses.

ifconfig

Sample Output:

eth0      Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.125  Bcast:172.16.16.100  Mask:255.255.255.224
          inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1385 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1249 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:127317 (124.3 KiB)  TX bytes:200787 (196.0 KiB)
          Interrupt:18 Base address:0x2000

eth0:0     Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.126  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.127  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.128  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:3    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.129  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

eth0:4    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C
          inet addr:172.16.16.130  Bcast:172.16.16.100  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:18 Base address:0x2000

By following these methods, you can effectively create and manage multiple IP addresses on a single network interface in Red Hat Enterprise Linux systems. This flexibility enables you to optimize network communication and connectivity according to your specific requirements.

Narad Shrestha
He has over 10 years of rich IT experience which includes various Linux Distros, FOSS and Networking. Narad always believes sharing IT knowledge with others and adopts new technology with ease.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

84 thoughts on “How to Assign Multiple IPs to a Single Network Interface in Linux”

  1. So if the server/system is initiating traffic, which IP will be used as the source. Can we define which source IP needs to be used when the server is initiating any traffic?

    Reply
  2. I tried it in virtual box multiples interface not reflecting in ifconfig however it’s showing as network available but at a time only one interface is working and tried to ping other interfaces like eth0:2,3,4 from eth0 its showing Destination host unreachable

    Reply
    • given a text file like (lots of white space)

      eth0 4.2.2.2   primary
      eth0:2    5.2.2.2              alias
      eth0:3            6.3.3.3  alias
      
      $ cat file | column -t
      
      Reply
  3. Thanks for the easy to understand tutorial. I just want to point out a minor correction that got me a bit confused. In the 3rd table, which I copied below, the ip addresses are missing a “1” after the last decimal as “.25” should be “.125”, “.26” should be “.126″…etc.

    Adapter IP Address Type
    ————————————————-
    eth0 172.16.16.25 Primary
    eth0:0 172.16.16.26 Alias 1
    eth0:1 172.16.16.27 Alias 2
    eth0:2 172.16.16.28 Alias 3

    This should be the correct table consistent with the ip addresses used in the example by the author:

    Adapter IP Address Type
    ————————————————-
    eth0 172.16.16.125 Primary
    eth0:0 172.16.16.126 Alias 1
    eth0:1 172.16.16.127 Alias 2
    eth0:2 172.16.16.128 Alias 3

    Reply
  4. Nice explanation. I like this site very much. Every thing can be understood very easily and precisely​.
    Many thanks !!

    Reply
    • If you want to create a virtual interface with some subnet, the respective subnet should be physically connected to the machine

      Reply
    • @Gaurav,

      Assigning multiple IP addresses means creating multiple NIC’s using one single Network interface with each different name and different IP..

      Reply
  5. Hello, Nice tutorial by the way. I have a question. I have configured two aliases on my NIC card eth0 (eth0:1 and eth0:2). However, I do not want them to be persistence.

    What I noticed though is that each time I make a change to the eth0:1 interface, the eth0:2 interface is deleted whereas the reverse is not true.

    Does it mean that changed to the lower other alias deletes the higher order i.e. ifconfig eth0:1 xxx.xxx.xx.xx delete eth0:2 ?

    Thanks so much for your kind assistance.

    Reply
    • @Anne,

      No that shouldn’t happen and each alias Network NIC is configured individually and work independently, this is something I really don’t’ understand, you need to check your configurations properly..

      Reply
  6. Hi,

    After I’m editing it using vi command for each ifcfg eth0:0 and eth0:1, then i want to check back if I’m inserting it correctly using command:

    # /etc/init.d/network restart
    

    then after that the output is “[failed]”

    then insert it “ifconfig” then it shows “command not found”, can i ask u guys, why this happens?

    Reply
    • @Haru,

      Please add the correct values to those ifcf interface files and about ifconfig command missing, you need to install it using yum package manager..

      Reply
    • @Ashwin,

      I hope you running that command as root user, if not switch to root user and execute, it needs root privileges to execute that command.

      Reply
    • @Dilip,

      To add a permanent static route on CentOS, RHEL or Fedora distributions, use the following command.

      # echo "192.168.10.0/16 via 192.168.5.5" >> /etc/sysconfig/network-scripts/route-eth0
      

      If you’re using Debian or Ubuntu distribution, try to run the following command to add a static route permanently.

      # echo "up route add -net 192.168.10.0/16 gw 192.168.5.5 dev eth0" >> /etc/network/interfaces
      

      Don’t forget to replace the IP address with your route IP address

      Reply
  7. typo…

    [root@ctos67 ~]# ip a s eth0
    2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:1c:9e:77 brd ff:ff:ff:ff:ff:ff
    inet 192.168.123.2/24 brd 192.168.123.255 scope global eth0
    inet6 fe80::5054:ff:fe1c:9e77/64 scope link
    valid_lft forever preferred_lft forever

    [root@ctos67 ~]# for i in {10..20}; do ip a a 192.168.123.${i}/24 dev eth0:$i; done
    [root@ctos67 ~]# ip a s eth0
    2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:1c:9e:77 brd ff:ff:ff:ff:ff:ff
    inet 192.168.123.2/24 brd 192.168.123.255 scope global eth0
    inet 192.168.123.10/24 scope global secondary eth0
    inet 192.168.123.11/24 scope global secondary eth0
    inet 192.168.123.12/24 scope global secondary eth0
    inet 192.168.123.13/24 scope global secondary eth0
    inet 192.168.123.14/24 scope global secondary eth0
    inet 192.168.123.15/24 scope global secondary eth0
    inet 192.168.123.16/24 scope global secondary eth0
    inet 192.168.123.17/24 scope global secondary eth0
    inet 192.168.123.18/24 scope global secondary eth0
    inet 192.168.123.19/24 scope global secondary eth0
    inet 192.168.123.20/24 scope global secondary eth0
    inet6 fe80::5054:ff:fe1c:9e77/64 scope link
    valid_lft forever preferred_lft forever

    [root@ctos67 ~]# for i in {10..20}; do ip a d 192.168.123.${i}/24 dev eth0:$i; done
    [root@ctos67 ~]# ip a s eth0
    2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:1c:9e:77 brd ff:ff:ff:ff:ff:ff
    inet 192.168.123.2/24 brd 192.168.123.255 scope global eth0
    inet6 fe80::5054:ff:fe1c:9e77/64 scope link
    valid_lft forever preferred_lft forever

    Reply
  8. I’d like to use ip command to temporarily create multiple ip address.

    for i in {0..10}; do ip a a 192.168.123.${i}/24 dev eth0:${i}; done

    Reply
    • Set up a new Ubuntu 16 64bit Server. Need to bind the full /22 IPv4 as static. I can only ping .2 from the outside, but not the remainder and I’m stuck here.

      auto eno1
      iface eno1 inet static
      address xxx.xxx.16.2
      netmask 255.255.252.0
      network xxx.xxx.16.0
      broadcast xxx.xxx.19.255
      gateway xxx.xxx.16.1
      # dns-* options are implemented by the resolvconf package, if installed
      dns-nameservers 8.8.8.8 8.8.4.4
      dns-search domain.com

      This method won’t work

      root@server:~# ip addr add xxx.xxx.16.1/22 dev eno1
      root@server:~# ip addr show
      1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
      inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
      2: eno1: mtu 1500 qdisc mq state UP group default qlen 1000
      link/ether d4:be:d9:ed:fb:8a brd ff:ff:ff:ff:ff:ff
      inet xxx.xxx.16.2/22 brd xxx.xxx.19.255 scope global eno1
      valid_lft forever preferred_lft forever
      inet xxx.xxx.16.1/22 scope global secondary eno1
      valid_lft forever preferred_lft forever
      inet6 fe80::d6be:d9ff:feed:fb8a/64 scope link
      valid_lft forever preferred_lft forever
      3: eno2: mtu 1500 qdisc noop state DOWN group default qlen 1000
      link/ether d4:be:d9:ed:fb:8c brd ff:ff:ff:ff:ff:ff
      4: eno3: mtu 1500 qdisc noop state DOWN group default qlen 1000
      link/ether d4:be:d9:ed:fb:8e brd ff:ff:ff:ff:ff:ff
      5: eno4: mtu 1500 qdisc noop state DOWN group default qlen 1000
      link/ether d4:be:d9:ed:fb:90 brd ff:ff:ff:ff:ff:ff

      root@server:~# ifconfig
      eno1: flags=4163 mtu 1500
      inet xxx.xxx.16.2 netmask 255.255.252.0 broadcast xxx.xxx.19.255
      inet6 fe80::d6be:d9ff:feed:fb8a prefixlen 64 scopeid 0x20
      ether d4:be:d9:ed:fb:8a txqueuelen 1000 (Ethernet)
      RX packets 28742 bytes 1879979 (1.8 MB)
      RX errors 0 dropped 0 overruns 0 frame 0
      TX packets 989 bytes 112470 (112.4 KB)
      TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

      root@server:~# echo “up route add -net xxx.xxx.16.0/22 gw xxx.xxx.16.1 dev eno1” >> /etc/network/interfaces
      root@server:~# nano /etc/network/interfaces

      All it did was add this line in interfaces file

      up route add -net xxx.xxx.16.0/22 gw xxx.xxx.16.1 dev eno1

      Reply
  9. Hi,

    Could you please provide some more info on more tips to add IP address from different network. how to decide the routing rules.

    Reply
  10. Hi, I want to create a virtual IP for my system against my sytsem IP to check and search keywords from different location and want to see the results. Is there any process or tool?

    Reply
  11. If I use the ifcfg-eth0-range0 range method, is it normal that it takes about 10+ minutes to restart network for each C class subnet?

    Also, if I want to add multiple C class ranges would I create them like this

    ifcfg-eth0-range0
    ifcfg-eth0-range0:1
    ifcfg-eth0-range0:2
    ifcfg-eth0-range0:3
    etc…?

    Reply
    • That’s because CENTOS / RHEL do some work in the background to make sure the network addresses aren’t being used elsewhere before turning them up. If you have large ranges, or a lot of smaller ranges, it’s just having to go through and check each network.

      Reply
  12. Hi
    I need to create multiple address on one NIC bond0 and bond0:1 but the address on bond0 need to be 0.0.0.0 and on bond0:1 any address on the network. the operating system is CentOs 7

    Reply
  13. In a single NIC configuration, does the BOOTPROTO have to be “static”, or can each be “dhcp” if reservations are on the DHCP server?

    I’ll answer my own question (perhaps) with an assumption of yes, since a DHCP server won’t be able to farm out to IP’s to the same MAC… true?

    Reply
  14. sir
    Example:

    I have lan connection and wifi connection for Desktop and laptop with staic ip
    Range is given below for example
    172.125.10.1 to 172.125.10.254

    Some Peoples are using static ip in mobile and tablet,,How to block it those device and any free tools are available or what

    Any procedure means in centos or windows Please tell me

    Reply
  15. Hi! Please tell me how to configure ipv6 for different interfaces without using the settings interface ipv4, is it possible at all on centos?
    n the interface settings should I prescribe the following:
    DEVICE=eth0:0
    BOOTPROTO=static
    ONBOOT=yes
    IPV6INIT=yes
    IPV6ADDR=2a01:230:2:6::9eb/64

    but the resulting console responds:
    error in ifcfg-eth0:0: didn’t specify device or ipaddr

    Reply
  16. [root@kraj-garth ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0-range0
    DEVICE=eth0
    HWADDR=00:50:56:bb:20:71
    ONBOOT=yes
    BOOTPROTO=none
    GATEWAY=10.95.107.1
    DNS1=10.95.158.2
    NETMASK=255.255.255.0
    TYPE=Ethernet
    IPV6INIT=no
    IPADDR_START=10.95.107.160
    IPADDR_END=10.95.107.200
    USERCTL=no

    but not able to create mulitple ips

    Reply
  17. Creating multiple aliases for a single physical NIC and assigning them IP’s belonging to different subnet will decrease the throughput of the NIC for a particular subnet, Right ???

    If I want to transfer data from 2 different subnets to one server, then for attaining a good throughput I should deploy 2 separate NIC interfaces for the traffic from each of the subnets, Right??

    Please let me know if I am wrong and provide your suggestions regarding the same as well.

    Thanks
    Pawan

    Reply
  18. Hello,
    now i want to assign hostname for each of ipaddress . that can be done by adding entries in /etc/hosts file. but what entry needs to e done in “/etc/sysconfig/network” file?.
    Thanks in advance.
    Subbu

    Reply
  19. Hi,
    I have assigned an ip alias on one Ethernet card
    the ifconfig output shows both of them correctly but when I
    unplug cable and plug it, just second Ip Address is
    active and can be ping.
    Any solution will be appreciated.

    Reply
  20. IP alias with NetworkManager on FC17 does not work as given here!
    Nor does the method where all IL alais are given as:

    IPADDR0
    IPADDR!
    etc.

    BB

    Reply
  21. Hi

    I have configured virtual interfaces when I run ifconfig they appears, but in the network manager just permit one connection, in the end one network exist for the clients is like 8021q is not working any idea_?

    Reply
  22. Hi,
    My Linux servers has 6 ipaddress(3 eth ) . if I execute hostname -I (capital ‘eye’) I get 6 ipaddress (eth0, etho:0,eth1, eth1:0,eth2, eth2:0) and when I execute hostname -i( smal ‘eye’) I get the ipaddres of eth0 in which I am unable to ping because I dont have access but I do have access to eth2 and eth2:0 .
    How do I change in such a way that hostname -i displays the ipaddress of eth2 rather than eth0

    Reply
  23. Hi used exactly your commands to try and create the virtual interface, but it didn’t work for me.

    I am using Fedora 13. The syntax at the shell is: service network restart. Then I ran ifconfig and it showed eth0, eth1, and lo – no eth0:1.

    This is what my ifcfg-eth0 file looks like:

    DEVICE=eth0
    ONBOOT=yes
    TYPE=Ethernet
    BOOTPROTO=none
    DNS1=xxx.xxx.xxx.4
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME=”System eth0″
    UUID=xxxxx
    DNS2=xxx.xxx.xxx.6
    HWADDR=xx
    IPADDR0=xxx.xxx.xx.242
    PREFIX0=28
    GATEWAY0=xxx.xxx.xx.241

    This is what I used for my ifcfg-eth0:1

    DEVICE=eth0:1
    ONBOOT=yes
    TYPE=Ethernet
    BOOTPROTO=none
    NAME=”System eth0:1″
    HWADDR=xx
    IPADDR0=xxx.xxx.xx.243
    PREFIX0=28
    GATEWAY0=xxx.xxx.xx.241

    I don’t know what the “IPADDR0” – the zero is for.

    I read the note from your other user who says to add

    IPADD1
    IPADD2

    directly into the ifcfg-eth0, file.

    When I did that, the network interface is still eth0 – no eth0:1, and it had the last IP address mentioned in the list – so it didn’t create multiple virtual interfaces.

    Reply
  24. Hi narad,

    I am configuring multiple addresses in my “rc.local” file using:

    ifconfig eth0:1 199.199.199.199 netmask 255.255.255.199
    route add -host 199.199.199.199 dev eth0

    ifconfig eth0:2 199.199.199.200 netmask 255.255.255.199
    route add -host 199.199.199.200 dev eth0

    ———-

    When I used to have only 2 or 3 of these, on boot the interfaces would get setup.

    But now my rc.local file has 10 interfaces and a long firewall startup script.

    I am finding that if my ethernet adapter or upstream router is unplugged temporarily, I lose all the network settings and have to reissue above command.

    Also, on startup, it doesn’t execute my long firewall script, I have to drop all rules, reissues the “ifconfig” command and then rerun the rules in the shell.

    Will your solution solve this problem?

    Reply
  25. i am using Static IP, that is eth0= x.x.x.1

    using aliases as mentioned below like wise

    eth0:0=x.x.x.2
    eth0:1=x.x.x.3
    eth0:2=x.x.x.4
    eth0:3=x.x.x.5

    i want to monitor the rotation of the IPS (what is the time intervals between the IP rotation?) how can i check it ?

    Reply
  26. . I am very happy to see here about assigning Multiple IPs for a single interface.

    . I want to monitor interval timings between the multiple IPs(eth0 and aliases) rotation.

    . how can i check it ?

    Adv..Thanks

    ………………………………
    aFriend

    Reply
    • Rotation? Are you referring to dhcp renewals or bonding load balancing via round-robin? If it’s bonding, having both on the same physical interface is worthless. If it’s dhcp renewals, just scan /var/log/messages or your dhcp server logs filtering out just your MAC address.

      Reply
    • You can open any IP Aliasing device in iptables, by below rule. Just replace “eth0:1” with your IP Aliasing device name.

      # iptables -A INPUT -m state --state NEW -p tcp -i eth0:1 -j ACCEPT
      
      Reply
    • Yes. It should be doing that by default unless you disabled IPV6. Notice the inet6 section of ip addr show.

      # ip addr show eth1
      3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:25:b5:01:10:0e brd ff:ff:ff:ff:ff:ff
      inet 192.168.40.44/16 brd 192.168.255.255 scope global eth1
      inet6 fe80::225:b5ff:fe01:100e/64 scope link
      valid_lft forever preferred_lft forever

      Reply
  27. Also, as a quick (temporary) solution, you can use either the ifconfig or ip commands:

    Example:
    ip address add 10.10.20.1/24 dev eth0:0

    or

    ifconfig eth0:0 10.10.20.1/24 up

    These will not persist after a reboot, they are temporary and may come in handy for things like connecting to a new router to configure it, or quickly connect to a misconfigured PC on your network.

    Besides rebooting, you can bring these down manually like this:

    ip address delete 10.10.20.1/24 dev wlp1s0:0

    or

    ifconfig wlp1s0:0 down

    Cheers!

    Reply
    • oops… I was testing these commands on my laptop so the commands to bring the temporary aliased IPs should actually be:

      ip address delete 10.10.20.1/24 dev eth0:0
      or
      ifconfig eth0:0 down

      Note that the device should match one of your devices (with :0 after it) as seen by:

      ifconfig

      or

      ip address show

      Each new alias you add (if more than 1) should go up in number as seen in the authors example.

      Reply
  28. How about IPv6?

    It seems a totally different story. The difference on Multiple IPs between IPv4 and IPv6 will confuse many linuxers.

    Reply
  29. Both the ifconfig command and the ethx:y syntax have been obsolete for more than a decade (since the 2.4 kernel came out).

    The correct way to manually add an IP address to an interface is:
    ip addr add 172.16.16.126/27 dev eth0

    The correct way to set this up on a RedHat system is in the ifcfg-eth0 file add additional lines such as:
    IPADDR2=172.16.16.127
    NETMASK2=255.255.255.224

    The correct way to list the IPs on a system is ‘ip addr ls’. The ifconfig command is not compatible with the modern networking features of the Linux kernel.

    Reply
    • Thanks I was going to say the same thing. Please don’t use aliases. They aren’t supported any more and you’ll even run into issues where the interface aliases don’t always come up on a reboot.

      Use ‘ip addr show’ rather than ifconfig to see interfaces.

      Reply
    • Thank you very mutch, i use this soution :

      IPADDR1=172.16.16.127
      NETMASK1=255.255.255.224

      IPADDR2=172.16.16.127
      NETMASK2=255.255.255.224

      but there is one eth interface in eth0: ip addr ls

      link/ether 00:0c:29:66:6d:a8 brd ff:ff:ff:ff:ff:ff
      inet 192.168.0.17/16 brd 192.168.255.255 scope global eth0
      inet 192.168.10.10/16 brd 192.168.255.255 scope global secondary eth0
      inet 192.168.10.11/16 brd 192.168.255.255 scope global secondary eth0
      inet6 fe80::20c:29ff:fe66:6da8/64 scope link
      valid_lft forever preferred_lft forever

      i will use it for virtualhost.

      Reply
  30. Hi, and thank you for sharing this article. One question, make sense to assign IP addresses for different networks in the same network interface, e.g. 192.168.21.3, 10.0.0.4, 172.16.16.220?

    Reply
    • generally, all Alias IP should be from same VLAN which means you can’t. I hope, still network admin dont have any way to allign different VLAN on same interface

      Reply
    • Yes, you can have your aliases on different subnets. I use that as a “poor man’s VLAN” – you can have different networks on the same physical network without having to use managed switches. Machines on the different networks will generally have very little influence on each other, and unless the user knows what they are doing (such as by reading this article…), they can’t access other systems.

      I also find it very useful for testing and configuring network equipment and other devices. I have a spare ethernet port that is configured with 192.168.1.2, 192.168.2.2, 192.168.99.2, and similar addresses, for convenience when working with routers or other devices with fixed IP addresses.

      Reply
    • @Chaitanya Yes, create interface for different Subnet as “ifcfg-eth0-range1” and give parameter range as shown above.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.