IP Aliasing: Difference between revisions

From Leo's Notes
This page was last edited on 14 June 2020, at 21:55.
No edit summary
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 2: Line 2:


== Linux ==
== Linux ==
To add an additional IP address to a network device, such as eth0:
Use the {{code|ip}} command to add or remove IP addresses from an interface.
ifconfig eth0:0 10.1.1.2 up
 
{{highlight|lang=terminal|code=
# ip address add $ip/$mask dev $interface
# ip address del $ip/$mask dev $interface
}}


To make it persistent, create a ifcfg script with the IP changes:
To make it persistent, create a ifcfg script with the IP changes:
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
{{highlight|lang=terminal|code=
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
NAME=eth0:0
DEVICE=eth0:0
IPADDR=10.1.1.2
NAME=eth0:0
NETMASK=255.255.255.0
IPADDR=10.1.1.2
ONBOOT=yes
NETMASK=255.255.255.0
 
ONBOOT=yes
}}


Ensure that there is no gateway set in the ifcfg-eth0 file because it should be set in /etc/sysconfig/network.
Ensure that there is no {{code|GATEWAY}} set in the {{code|ifcfg-eth0}} file because it should be set in {{code|/etc/sysconfig/network}}.


== FreeBSD ==
== FreeBSD ==
Under FreeBSD, to add an additional IP address (10.1.1.2, with a netmask of 255.255.255.0) to <code>re0</code>, run:
Under FreeBSD, to add an additional IP address (10.1.1.2, with a netmask of 255.255.255.0) to {{code|re0}}, run:


ifconfig re0 10.1.1.2 netmask 255.255.255.255 alias
{{highlight|lang=terminal|code=
# ifconfig re0 10.1.1.2 netmask 255.255.255.255 alias
}}


The changes above are not persistent and will not survive a reboot. Add the following to <code>[[/etc/rc.conf]]</code> to make it persistent:
The changes above are not persistent and will not survive a reboot. Add the following to {{code|[[/etc/rc.conf]]}} to make it persistent:


ifconfig_re0_alias0="10.1.1.2 netmask 255.255.255.255 alias"
{{highlight|lang=terminal|code=
# ifconfig_re0_alias0="10.1.1.2 netmask 255.255.255.255 alias"
}}


[[Category:FreeBSD]]
[[Category:FreeBSD]]
{{Navbox Linux}}[[Category:Linux]]
[[Category:Networking]]

Latest revision as of 21:55, 14 June 2020

IP Aliasing is the process of adding additional IP addresses to a single network interface.

Linux

Use the ip command to add or remove IP addresses from an interface.

# ip address add $ip/$mask dev $interface
# ip address del $ip/$mask dev $interface

To make it persistent, create a ifcfg script with the IP changes:

# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
NAME=eth0:0
IPADDR=10.1.1.2
NETMASK=255.255.255.0
ONBOOT=yes

Ensure that there is no GATEWAY set in the ifcfg-eth0 file because it should be set in /etc/sysconfig/network.

FreeBSD

Under FreeBSD, to add an additional IP address (10.1.1.2, with a netmask of 255.255.255.0) to re0, run:

# ifconfig re0 10.1.1.2 netmask 255.255.255.255 alias

The changes above are not persistent and will not survive a reboot. Add the following to /etc/rc.conf to make it persistent:

# ifconfig_re0_alias0="10.1.1.2 netmask 255.255.255.255 alias"