Introduction

...

Add Additional Static IP Address

First make sure you know how your current network looks on your server with the already assigned IP address,

ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3c:3f:68:7f  
          inet addr:64.73.220.110  Bcast:64.73.220.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3cff:fe3f:687f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1677062 errors:0 dropped:952 overruns:0 frame:0
          TX packets:11659 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:88552695 (88.5 MB)  TX bytes:2706451 (2.7 MB)
# you will see more but ignore
 
cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
 
# get gateway
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         64.73.220.1     0.0.0.0         UG    0      0        0 eth0
10.0.3.0        0.0.0.0         255.255.255.0   U     0      0        0 lxcbr0
64.73.220.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
 
# Get name servers,
cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 216.15.129.205
nameserver 216.15.129.206

Key things to note is your ethernet card device name (usually eth0), mask, gateway and name servers. In this example,

Network AttributeValue
ethernet card deviceeth0
mask255.255.255.0
gateway64.73.220.1
name servers

216.15.129.205
216.15.129.206

 

Temporary to Test

You may use the ifconfig or ip command. I like the ifconfig as you do not need to calculate the netmask from Dotted Decimal to Bitmask (Bits). I also noticed a difference between the two commands. With the ifconfig, a brd number is added. I have no idea what the brd number is used for. Both approaches do work. 

In this example, we will add 64.73.220.110 to the existing ethernet card.

ifconfig Approach

This approach has a brd number,

# syntax with add or del to add or delete the ip
# ip address add/del [ip]/[mask-digits] dev [nic]
ifconfig eth0:0 64.73.220.117 netmask 255.255.255.0 up


# verify new address shows up,
ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3c:3f:68:7f brd ff:ff:ff:ff:ff:ff
    inet 64.73.220.110/24 brd 64.73.220.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 64.73.220.111/24 brd 64.73.220.255 scope global secondary eth0:0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3cff:fe3f:687f/64 scope link 
       valid_lft forever preferred_lft forever
3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether fe:33:d8:e0:ef:6b brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
       valid_lft forever preferred_lft forever
    inet6 fe80::b06f:d2ff:fe9d:49be/64 scope link 
       valid_lft forever preferred_lft forever
5: vethHVREWV: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master lxcbr0 state UP group default qlen 1000
    link/ether fe:33:d8:e0:ef:6b brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc33:d8ff:fee0:ef6b/64 scope link 
       valid_lft forever preferred_lft forever

ip Approach

This approach results in not brd number  and you need to make sure to calculate the netmask from Dotted Decimal to Bitmask (Bits). In this case, 255.255.255.0 = 24,

# syntax with add or del to add or delete the ip
# ip address add/del [ip]/[mask-digits] dev [nic]
sudo ip address add 64.73.220.111/24 dev eth0
 
# verify new address shows up,
ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3c:3f:68:7f brd ff:ff:ff:ff:ff:ff
    inet 64.73.220.110/24 brd 64.73.220.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 64.73.220.111/24 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3cff:fe3f:687f/64 scope link 
       valid_lft forever preferred_lft forever
3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether fe:33:d8:e0:ef:6b brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
       valid_lft forever preferred_lft forever
    inet6 fe80::b06f:d2ff:fe9d:49be/64 scope link 
       valid_lft forever preferred_lft forever
5: vethHVREWV: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master lxcbr0 state UP group default qlen 1000
    link/ether fe:33:d8:e0:ef:6b brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc33:d8ff:fee0:ef6b/64 scope link 
       valid_lft forever preferred_lft forever

Add a permanent IP Address

To make the changes permanent modify the /etc/network/interfaces with the following syntax,

auto [NIC]:[n]
iface [NIC]:[n] inet static
address [ip.add.rr.ss]
gateway [gw.ip.ad.rs]
netmask [ne.tm.as.kk]

Continuing with the example the full file would look like this,

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

# Second IP
auto eth0:1
iface eth0:1 inet static
address 64.73.220.111
gateway 64.73.220.1
netmask 255.255.255.0
dns-nameservers 216.15.129.205 216.15.129.206

Based on my home server work, name server entries are required for static entries. But in this this case, it is a second entry and resolv.conf has the name servers listed from the first dhcp assigned network card. Will test how this pans out without name server first then update here if needed.

References

Best article yet - https://www.garron.me/en/linux/add-secondary-ip-linux.html


# syntax ifconfig [nic]:0 [IP-Address] netmask [mask] upsudo ifconfig eth0:0 64.73.220.110 netmask 255.255.255.0 up