How to assign multiple IP addresses to single Network card in Linux

You may also like...

  • AlekseyShi

    My solution to make multiple addresses.
    1. With netctl
    [root@localhost ~]# pacman -S netctl
    [root@localhost ~]# cp /etc/netctl/examples/ethernet-static /etc/netctl/enp3s0
    Description=’A basic static ethernet connection’
    Interface=enp3s0
    Connection=ethernet
    IP=static
    Address=(‘192.168.0.23/24’ ‘192.168.3.23/24’)
    Routes=(‘192.168.0.0/16 via 192.168.3.1′)
    Gateway=’192.168.0.1’
    DNS=(‘192.168.0.1’)
    ## For IPv6 autoconfiguration
    #IP6=stateless
    ## For IPv6 static address configuration
    #IP6=static
    #Address6=(‘1234:5678:9abc:def::1/64’ ‘1234:3456::123/96’)
    #Routes6=(‘abcd::1234′)
    #Gateway6=’1234:0:123::abcd’
    [root@localhost ~]# netctl start enp3s0
    [root@localhost ~]# netctl status enp3s0

    2. With nmcli
    [root@localhost ~]# nmcli connection add con-name myEthernet ifname net0 autoconnect no type ethernet ip4 192.168.0.64/24 gw4 192.168.0.1

    root@localhost qq]# nmcli connection modify myEthernet +ipv4.addresses 192.168.3.64/24
    root@localhost qq]# nmcli c mod myEthernet ipv4.routes ‘192.168.0.0/16 192.168.3.1’
    root@localhost qq]# nmcli connection up myEthernet
    root@localhost qq]# nmcli connection show myEthernet

    • SK

      Thanks for sharing.

  • Anders Jackson

    192.168.0.0/16 are not a A class IP-V4 address, it is a C-class.
    So, intstead of guessing wrong, use the command sipcalc(1) or ipcalc(1) to calculat the propper masks and ip addresses.

    $ sudo apt-get install sipcalc

    $ sipcalc 192.168.1.1/24
    -[ipv4 : 192.168.1.1/24] – 0

    [CIDR]
    Host address – 192.168.1.1
    Host address (decimal) – 3232235777
    Host address (hex) – C0A80101
    Network address – 192.168.1.0
    Network mask – 255.255.255.0
    Network mask (bits) – 24
    Network mask (hex) – FFFFFF00
    Broadcast address – 192.168.1.255
    Cisco wildcard – 0.0.0.255
    Addresses in network – 256
    Network range – 192.168.1.0 – 192.168.1.255
    Usable range – 192.168.1.1 – 192.168.1.254


    $ sipcalc 192.168.1.1 255.255.255.0
    -[ipv4 : 192.168.1.1 255.255.255.0] – 0

    [CIDR]
    Host address – 192.168.1.1
    Host address (decimal) – 3232235777
    Host address (hex) – C0A80101
    Network address – 192.168.1.0
    Network mask – 255.255.255.0
    Network mask (bits) – 24
    Network mask (hex) – FFFFFF00
    Broadcast address – 192.168.1.255
    Cisco wildcard – 0.0.0.255
    Addresses in network – 256
    Network range – 192.168.1.0 – 192.168.1.255
    Usable range – 192.168.1.1 – 192.168.1.254


    $ echo “Also try different options, like -c”

    And use IPv6 instread of IPv4, as IPv6 is supposed to handle many addresses in all machines. IPv4 not so much.

    • SK

      Great stuff. Thank you.