...
First make sure you know how your current IP Address setting looksnetwork looks on your server with the already assigned IP address,
Code Block | ||
---|---|---|
| ||
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 |
Key things to note is your ethernet card device name (usually eth0), mask and Maskgateway. In this example,
Network Attribute | Value |
---|---|
ethernet card device | eth0 |
mask | 255.255.255.0 |
gateway | 64.73.220.1 |
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.
...
Add a permanent IP Address
Edit the To make the changes permanent modify the /etc/network/interfaces with the following syntax,
Code Block | ||
---|---|---|
| ||
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,
Code Block | ||
---|---|---|
| ||
# 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 |
References
Best article yet - https://www.garron.me/en/linux/add-secondary-ip-linux.html
...