Linux command to remove virtual interfaces or network aliases

How do I remove virtual interfaces such as eth0:1 or eth1:1?

Use the ifconfig command or ip command to remove virtual interfaces or network aliases under Linux operating systems. The ip or deprecated ifconfig command is used to configure the kernel-resident network interfaces. It is used at Linux boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed. Please note that network IP Aliases are not real network devices, but programs should be able to configure and refer to them, as usual, using the ifconfig, ip, and route commands. These are used to assign multiple ip addresses to a single network interface on your Linux machine. So, for example, I can have five usable public IPv4 assigned to the eth0 interface to host five different web apps, each with a unique IPv4 address. Let us see how to remove virtual interfaces or network aliases under Linux.

Tutorial details
Difficulty levelEasy
Root privilegesYes
RequirementsLinux terminal
CategoryNetwork Utilities
OS compatibilityAlma • Alpine • Arch • Debian • Fedora • Linux • Mint • openSUSE • Pop!_OS • RHEL • Rocky • Stream • SUSE • Ubuntu
Est. reading time3 minutes

ADVERTISEMENT

Listing Linux interfaces

Type any one of the following command to get a list of NICs (network interface cards) on Linux:
# ip link show
# get info about eth0 or enp0s31f6 NIC #
# ip addr show enp0s31f6

Here is what you may see:

2: enp0s31f6:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 48:2a:e3:5c:16:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.25/24 brd 192.168.2.255 scope global dynamic noprefixroute enp0s31f6
       valid_lft 6354sec preferred_lft 6354sec
    inet 192.168.2.31/24 scope global secondary enp0s31f6
       valid_lft forever preferred_lft forever
    inet 192.168.2.32/24 brd 192.168.2.255 scope global secondary enp0s31f6:0
       valid_lft forever preferred_lft forever
    inet6 fe80::4a2a:e3ff:fe5c:16bc/64 scope link 
       valid_lft forever preferred_lft forever

Or use the ifconfig command on older systems:
# ifconfig -a
# filter out results using the grep command #
# ifconfig -a | grep -A 6 eth0

Outputs:

eth0: flags=4163  mtu 1500
        inet 192.168.2.25  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::4a2a:e3ff:fe5c:16bc  prefixlen 64  scopeid 0x20
        ether 48:2a:e3:5c:16:bc  txqueuelen 1000  (Ethernet)
        RX packets 23858  bytes 21803276 (21.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17321  bytes 7183523 (7.1 MB)
--
eth0:1: flags=4163  mtu 1500
        inet 192.168.2.32  netmask 255.255.255.0  broadcast 192.168.2.255
        ether 48:2a:e3:5c:16:bc  txqueuelen 1000  (Ethernet)
        device interrupt 16  memory 0xee500000-ee520000  

Linux command to remove virtual interfaces or network aliases

Open the terminal application. Type the following command to remove eth0:1 alias using the ifconfig command# ifconfig eth0:1 down
# ifconfig -a
# ifconfig -a | grep -A 6 eth0

Another option on modern Linux distro is the ip command as follows to deletes the alias:
# ip address del 192.168.2.31/24 dev eth0

/etc/sysconfig/network-scripts/ifcfg-ethX-range0 file

To remove interface permanently edit network configuration file stored at /etc/directory. For Red Hat / Fedora Core file stored in /etc/sysconfig/network-scripts/ directory. For Debian or Ubuntu Linux just edit file /etc/network/interfaces and remove the entries. For example open file called /etc/sysconfig/network-scripts/ifcfg-eth1-range0 file using a text editor such as vi/vim or nano:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0
You will see network aliases configuration:
IPADDR_START=192.167.1.5
IPADDR_END=192.167.1.100
CLONENUM_START=0
NETMASK=255.255.255.0


Just comment out everything or just rename the file using the mv command:
# mv /etc/sysconfig/network-scripts/ifcfg-eth0-range0 /etc/sysconfig/network-scripts/working.ifcfg-eth0-range0.backup
Finally, restart Linux network service:
# service network restart
OR use the systemctl command on modern Linux distro:
# systemctl restart netwrok

Summing up

Typically we add the IP address 1.2.3.4 to the eth0 network interface as eth0:1:
# ifconfig eth0:1 1.2.3.4 up
And then delete when work is done:
# ifconfig eth0:1 down
However, with modern Linux distro we use the ip command. To add:
# ip address add 1.2.3.4 dev eth0
To delete:
# ip address del 1.2.3.4 dev eth0
The config file for aliases on a RHEL and co located in the /etc/sysconfig/network-scripts/ifup-aliases or /etc/sysconfig/network-scripts/ifcfg-eth1-range0. For Debian/Ubuntu Linux look into /etc/network/interfaces file. Also read the following manual pages using the man command or help command:
$ man ip
$ man ifconfig

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值