How To Assign Multiple IP Addresses To Single Network Card In Linux

assign multiple ip addresses

6 Responses

  1. AlekseyShi says:

    My solution to make multiple addresses.
    1. With netctl
    [[email protected] ~]# pacman -S netctl
    [[email protected] ~]# 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’
    [[email protected] ~]# netctl start enp3s0
    [[email protected] ~]# netctl status enp3s0

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

    [email protected] qq]# nmcli connection modify myEthernet +ipv4.addresses 192.168.3.64/24
    [email protected] qq]# nmcli c mod myEthernet ipv4.routes ‘192.168.0.0/16 192.168.3.1’
    [email protected] qq]# nmcli connection up myEthernet
    [email protected]alhost qq]# nmcli connection show myEthernet

  2. Anders Jackson says:

    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.

  3. Jordi says:

    Nmcli is the way to go for Centos, Fedora, RHEL7 and above. The ifconfig command has been depricated. It will not show up interface device aliases and etc…
    So make sure NetworkManager service is running, or start it. Then check the full device interface configuration.

    Systemctl start NetworkManager

    Nmcli con show enp0s3

    Furthermore, with nmcli you can also script an IP address change remotely, change hostnames, assign connections SSID and passwords for wireless networks and more.

    Nmcli is definitely an efficient solution in the enterprise world

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.