- Configuring virtual IPs in Linux
- About this task
- Procedure
- Results
- What to do next
- Create Virtual/Secondary IP addresses on an Interface in Linux
- Create Virtual/Secondary IP addresses on an Interface in Linux
- Create Temporary Virtual/Secondary IP addresses on an Interface in Linux
- Create Permanent Virtual/Secondary IP addresses on an Interface in Linux
- Create Secondary IP addresses on CentOS and Similar RHEL derivatives.
- Create secondary IP addresses using nmcli command
- Create Secondary IP addresses using nmtui (Network Manager GUI)
- Create Secondary IP address on Ubuntu 18.04/Ubuntu 20.04 systems
- Create Secondary IP address on Debian systems
- Other Tutorials
- SUPPORT US VIA A VIRTUAL CUP OF COFFEE
- Виртуальный ip адрес линукс
Configuring virtual IPs in Linux
When you use a computer that is run on the Linux operating system and you want to configure virtual IP addresses so that the virtual IPs can then be configured as virtual clients in tests or as virtual servers in stubs.
Important: The steps for the task that are to be performed on the operating system are only indicative. The steps might vary depending on the version of the operating system. You might be able to use multiple methods to accomplish the task. You might already be aware of such methods. You can perform the task by following the on-screen instructions or by referring to the documentation provided by the operating system provider.
About this task
- The IP addresses that you create are legitimate.
- The IP addresses are available within the same subnet in the network.
- The IP addresses are blocked for distribution outside of the network.
Procedure
For example, to add the IP alias 10.134.59.4 to the network interface ens192 , run the following command:
# ip address add 10.134.59.4 dev ens192
Note: After you complete runs of the tests and stubs that used the virtual IPs, you must remove the virtual IPs that you configured by running the following command:
For example, to remove the IP alias 10.134.59.4 from the network interface ens192 , run the following command:
# ip address del 10.134.59.4 dev ens192
Results
What to do next
Create Virtual/Secondary IP addresses on an Interface in Linux
Follow through this tutorial to learn how to create virtual/secondary IP addresses on an interface in Linux. This enables you to assign multiple IP addresses to a single interface.
Create Virtual/Secondary IP addresses on an Interface in Linux
You can create virtual/secondary IP addresses on an interface in Linux temporarily or permanently.
Create Temporary Virtual/Secondary IP addresses on an Interface in Linux
To create temporary virtual/secondary IP addresses on an interface in Linux, you can use commands such as ip , ifconfig .
To use ip command to create/add secondary IP addresses to an interface, see the examples below.
In our example server, we have an interface called enp0s8 .
Checking the current IP address of the interface;
3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c4:23:c9 brd ff:ff:ff:ff:ff:ff inet 192.168.56.108/24 brd 192.168.56.255 scope global noprefixroute enp0s8 valid_lft forever preferred_lft forever inet6 fe80::d524:3777:b321:5ed/64 scope link noprefixroute valid_lft forever preferred_lft forever
The primary IP address assigned to the interface is 192.168.56.108 .
Assuming we want to temporarily assign a secondary IP address, 192.168.56.109 , to the interface using the ip command;
ip addr add 192.168.56.109/24 br 192.168.56.255 dev enp0s8
The addr and br are abbreviations for address and broadcast respectively.
Confirming the secondary IP address assignment;
3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c4:23:c9 brd ff:ff:ff:ff:ff:ff inet 192.168.56.108/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8 valid_lft 394sec preferred_lft 394sec inet 192.168.56.109/24 brd 192.168.56.255 scope global secondary enp0s8 valid_lft forever preferred_lft forever inet6 fe80::d524:3777:b321:5ed/64 scope link noprefixroute valid_lft forever preferred_lft forever
If you restart the networking/take the interface up and down or reboot your server, you will loose the assigned IP address.
Create Permanent Virtual/Secondary IP addresses on an Interface in Linux
Create Secondary IP addresses on CentOS and Similar RHEL derivatives.
Create secondary IP addresses using nmcli command
On CentOS and Similar derivatives, you can use simply use the NetworkManager command line tool, nmcli .
The command may not be available by default on Ubuntu/Debian systems. If so and want to use it, then install the network manager package ( network-manager ).
First confirm the interface connection name;
con is an abbreviation for connection .
NAME UUID TYPE DEVICE enp0s8 e59e1c2f-bda2-4704-9f4a-67e8cce636d9 ethernet enp0s8 Wired connection 1 a7d294d4-05d9-3724-832e-6b80dc288a24 ethernet enp0s3
In this case, we want to add virtual/secondary IP to interface enp0s8 , connection name enp0s8 .
This can be done using nmcli command as follows. Pay attention to plus(+)ipv4.addresses .
nmcli con mod enp0s8 +ipv4.addresses 192.168.56.109/24
mod is an abbreviation for modify .
Take down and bring up the interface. I Assume you are directly logged in via console and not via ssh.
nmcli con down enp0s8 && nmcli con up enp0s8
Confirm the secondary IP address assignment.
3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c4:23:c9 brd ff:ff:ff:ff:ff:ff inet 192.168.56.108/24 brd 192.168.56.255 scope global noprefixroute enp0s8 valid_lft forever preferred_lft forever inet 192.168.56.109/24 brd 192.168.56.255 scope global secondary noprefixroute enp0s8 valid_lft forever preferred_lft forever inet6 fe80::d524:3777:b321:5ed/64 scope link noprefixroute valid_lft forever preferred_lft forever
To remove the secondary IP address using nmcli command, just use minus(-)ipv4.addresses .
nmcli con mod enp0s8 -ipv4.addresses 192.168.56.109/24
nmcli con down enp0s8 && nmcli con up enp0s8
Create Secondary IP addresses using nmtui (Network Manager GUI)
nmtui is available if you have installed Network manager package.
Launch nmtui from the terminal (you can use tab key to navigate through the settings);
Select Edit a connection and click Ok.
Select the Interface to edit, which in this example is enp0s8 and click Edit;
Scroll down to IPV4 configuration and click Add and enter your IP address.
Next, click Ok at the bottom > Back > Activate a connection > Ok.
Select and deactivate the interface.
Select the interface and activate it again.
Select Back > Quit.
Confirm the IP address assignment.
3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c4:23:c9 brd ff:ff:ff:ff:ff:ff inet 192.168.56.108/24 brd 192.168.56.255 scope global noprefixroute enp0s8 valid_lft forever preferred_lft forever inet 192.168.56.109/24 brd 192.168.56.255 scope global secondary noprefixroute enp0s8 valid_lft forever preferred_lft forever inet6 fe80::d524:3777:b321:5ed/64 scope link noprefixroute valid_lft forever preferred_lft forever
You can similarly remove this using nmcli command or right from the nmtui tool.
Create Secondary IP address on Ubuntu 18.04/Ubuntu 20.04 systems
To create a permanent IP address on Ubuntu 18.04/Ubuntu 20.04 systems, which uses netplan to manage the network interfaces, then you can proceed as follows;
Check the current IP address for the interface;
3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:56:39:94 brd ff:ff:ff:ff:ff:ff inet 192.168.59.14/24 brd 192.168.59.255 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe56:3994/64 scope link valid_lft forever preferred_lft forever
The current netplan configuration for my interfaces;
cat /etc/netplan/00-installer-config.yaml
network: ethernets: enp0s3: dhcp4: true enp0s8: dhcp4: no addresses: [192.168.59.14/24] routes: - to: 0.0.0.0/0 via: 192.168.59.1 metric: 101 nameservers: addresses: [8.8.8.8] version: 2
To add a secondary IP address to the interface, edit the configuration file
cp /etc/netplan/00-installer-config.yaml
vim /etc/netplan/00-installer-config.yaml
Such that it may look like;
addresses: [192.168.59.14/24, 192.168.59.15/24]
The config now looks like;
network: ethernets: enp0s3: dhcp4: true enp0s8: dhcp4: no addresses: [192.168.59.14/24, 192.168.59.15/24] routes: - to: 0.0.0.0/0 via: 192.168.59.1 metric: 101 nameservers: addresses: [8.8.8.8] version: 2
Apply the configuration changes;
The confirm the IP address assignment
Create Secondary IP address on Debian systems
Similarly, update the interfaces as follows, to add the secondary IP address.
Sample interface configurations;
source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug enp0s3 iface enp0s3 inet dhcp auto enp0s8 iface enp0s8 inet static address 192.168.58.22 netmask 255.255.255.0 gateway 192.168.58.1 broadcast 192.168.58.255 dns-nameservers 8.8.8.8
To add a secondary IP address;
update the config as follows
source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug enp0s3 iface enp0s3 inet dhcp auto enp0s8 iface enp0s8 inet static address 192.168.58.22 netmask 255.255.255.0 gateway 192.168.58.1 broadcast 192.168.58.255 dns-nameservers 8.8.8.8 auto enp0s8:0 iface enp0s8:0 inet static address 192.168.58.23 netmask 255.255.255.0
auto enp0s8:0 iface enp0s8:0 inet static address 192.168.58.23 netmask 255.255.255.0
Save and exit the config and restart the networking;
systemctl restart networking
3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:2b:b4:61 brd ff:ff:ff:ff:ff:ff inet 192.168.58.22/24 brd 192.168.58.255 scope global enp0s8 valid_lft forever preferred_lft forever inet 192.168.58.23/24 brd 192.168.58.255 scope global secondary enp0s8:0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe2b:b461/64 scope link valid_lft forever preferred_lft forever
And that is it on how to create virtual/secondary IP addresses on an Interface in Linux.
Other Tutorials
SUPPORT US VIA A VIRTUAL CUP OF COFFEE
We’re passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!
Виртуальный ip адрес линукс
Linux — Виртуальные интерфейсы (дополнительные IP-адреса)
Linux — Виртуальные интерфейсы (дополнительные IP-адреса)
Здесь рассматривается добавление вторичного IP-адреса на физический интерфейс, система в данном случае — Red Hat Linux. Пример добавления интерфейса eth1:0, ассоциированного с физическим интерфейсом eth1:
ifconfig eth1:0 192.168.5.55 netmask 255.255.255.0 up
Чтобы интерфейс присутствовал после перезапуска, в /etc/sysconfig/network-scripts нужно создать соответствующий файл, в данном случае ifcfg-eth1:0 (последующие интерфейсы можно нумеровать последовательно, ifcfg-eth1:1, ifcfg-eth1:2 и так далее). Примерное его содержимое:
# 3Com Corporation 3c595 100BaseTX [Vortex]
Примечание: если нужно, чтобы при запуске интерфейс поднимался или, наоборот, не поднимался, следует воспользоваться параметром ONPARENT:
Он определяет, будет ли подниматься виртуальный интерфейс при поднятии родительского устройства (физического интерфейса).
- 50 Most Frequently Used UNIX / Linux Commands (With Examples)
- Alsa
- How to Find Files With setuid Permissions
- Installing Perl Modules
- Resume a large scp transfer
- Оптимизируем сетевую подсистему
- Оптимизируем процесс работы в консоли
- Монтирование образа шифрованного раздела
- wget
- tcpdump
- ssh tips
- inods limit
- error: ‘getpid’ was not declared in this scope(SOLVED)
- VGA Boot modes to set screen resolution
- Linux Professional Institute (LPI)
- SCP (от англ. secure copy)
- MultiBoot USB with Grub2
- Linux — Виртуальные интерфейсы (дополнительные IP-адреса)
- How to tar.gz
- Grub
- Distr version
- 4 Ways to Kill a Process – kill, killall, pkill, xkill
- xfreerdp
- Делаем Midnight Commander красивым
- Заварачиваем трафик. iptables и ssh
- Лекции основы
- Быстрый курс IPv6 в Linux
- Команды поиска GREP и FIND
- Монтирование удаленной папки с помощью sshfs
- Осваиваем 10 полезных приемов работы в UNIX
- Проверка зависимостей от библиотек ldd
- Просто о free
- Синхронизация времени
- hibernate
- How can I validate a video file from a script?
- Mplayer screensaver
- Mplayer with Xfce screensaver
- tshark&wireshark
- Route
- tshark decode unstandart tcp port
- Netem — Network Emulation
- How can a process intercept stdout and stderr of another process on Linux?
- How to find which ports are blocked
- non root tcpdump
- refreshing groups without having to re-login
- Simple Network Troubleshooting
- What does kill 0 do actually?