When we add a new or virtual network interface from the original physical interface, we might have to run some commands to bring up the new interface.
If any change is performed on NIC or if it’s down, then we have to run one of the below commands to bring them up.
It can be done by multiple ways and we would like to shortlist five best methods which can be used.
The commands are given below:
- ifconfig command: The ifconfig command is used configure a network interface. It provides a lot of information about NIC.
- ifdown/ifup Command: The ifdown command take a network interface down whereas the ifup command bring a network interface up.
- ip Command: ip command is used to manage NIC. It’s replacement of the old and deprecated ifconfig command. It’s similar to ifconfig command but has many powerful features which isn’t available with ifconfig command.
- nmcli Command: nmcli is a command-line tool for controlling NetworkManager and reporting network status.
- nmtui Command: nmtui is a curses‐based TUI application for interacting with NetworkManager.
ip command shows the available network interface card (NIC) information in the Linux system. According to the below output, two network interfaces (enp0s3 & enp0s8) are up and running in the system.
# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.1.4/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3 valid_lft 86049sec preferred_lft 86049sec inet6 fe80::3899:270f:ae38:b433/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:30:5d:52 brd ff:ff:ff:ff:ff:ff inet 192.168.1.3/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s8 valid_lft 86049sec preferred_lft 86049sec inet6 fe80::32b7:8727:bdf2:2f3/64 scope link noprefixroute valid_lft forever preferred_lft forever
1) Bringing UP/Down a Network Interface using ifconfig command
The ifconfig command is used to configure network interface.
It is run at boot time to set up network interfaces as required. It provides a lot of information about NIC. We can use ifconfig command when we want to make any changes on NIC.
Common Syntax for ifconfig:
# ifconfig [NIC_NAME] Down/Up
Run the following command to bring down the enp0s3
interface in the system. Please note, you have to enter the interface name that you want to bring down instead of “enp0s3”.
# ifconfig enp0s3 down
The given interface is down now as per the following output.
# ip a | grep -A 1 "enp0s3:" 2: enp0s3: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff
Please run the following command to bring up the enp0s3
interface in Linux.
# ifconfig enp0s3 up
After running the above command, the “enp0s3” interface is now running again according to the below output.
# ip a | grep -A 5 "enp0s3:" 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.1.4/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3 valid_lft 86294sec preferred_lft 86294sec inet6 fe80::3899:270f:ae38:b433/64 scope link noprefixroute valid_lft forever preferred_lft forever
2) How to enable and disable a Network Interface using ifdown/ifup command?
The ‘ifdown’ command take a network interface down whereas the ‘ifup’ command bring a network interface up.
Note: These commands doesn’t work on new interface device name like enpXXX
Common Syntax for ifdown/ifup:
# ifdown [NIC_NAME] # ifup [NIC_NAME]
Run the following command to bring down the eth1
interface.
# ifdown eth1
Run the following command to check if the given interface is down.
# ip a | grep -A 3 "eth1:" 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 08:00:27:d5:a0:18 brd ff:ff:ff:ff:ff:ff
Run the following command to bring up the eth1
interface.
# ifup eth0
The given interface is up now according to the below output.
# ip a | grep -A 5 "eth1:" 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:d5:a0:18 brd ff:ff:ff:ff:ff:ff inet 192.168.1.7/24 brd 192.168.1.255 scope global eth1 inet6 fe80::a00:27ff:fed5:a018/64 scope link tentative dadfailed valid_lft forever preferred_lft forever
ifup and ifdown doesn’t support the latest interface device enpXXX
names. We can see the below messages on running the command.
# ifdown enp0s8 Unknown interface enp0s8
3) Bringing UP/Down a Network Interface using ip command?
ip command is used to manage Network Interface Card (NIC). It’s replacement of old and deprecated ifconfig command on modern Linux systems.
It’s similar to ifconfig command but has many powerful features which isn’t available in ifconfig command.
Common Syntax for ip:
# ip link set Down/Up
Run the following command to bring down the enp0s3
interface.
# ip link set enp0s3 down
The interface is down now as per the following output.
# ip a | grep -A 1 "enp0s3:" 2: enp0s3: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff
Run the following command to bring up the enp0s3
interface.
# ip link set enp0s3 up
After running the above command, the “enp0s3” interface is now running again according to the below output.
# ip a | grep -A 5 "enp0s3:" 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.1.4/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3 valid_lft 86294sec preferred_lft 86294sec inet6 fe80::3899:270f:ae38:b433/64 scope link noprefixroute valid_lft forever preferred_lft forever
4) How to enable & disable a Network Interface using nmcli command?
nmcli is a command-line tool for controlling NetworkManager and reporting network status.
It can be used as a replacement for nm-applet or other graphical clients. nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.
Run the following command to identify the interface name because nmcli command performs most of the task using profile name
instead of device name
.
# nmcli con show NAME UUID TYPE DEVICE Wired connection 1 3d5afa0a-419a-3d1a-93e6-889ce9c6a18c ethernet enp0s3 Wired connection 2 a22154b7-4cc4-3756-9d8d-da5a4318e146 ethernet enp0s8
Common Syntax for nmcli:
# nmcli con Down/Up
Run the following command to bring down the enp0s3
interface. As stated, enter the profile name
instead of device name
to bring down the interface.
# nmcli con down 'Wired connection 1' Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
The interface is down now according to the below output.
# nmcli dev status DEVICE TYPE STATE CONNECTION enp0s8 ethernet connected Wired connection 2 enp0s3 ethernet disconnected -- lo loopback unmanaged --
Run the following command to bring up the enp0s3
interface. You have to give profile name
instead of device name
to bring it up.
# nmcli con up 'Wired connection 1' Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
Now the given interface is up as per the following output.
# nmcli dev status DEVICE TYPE STATE CONNECTION enp0s8 ethernet connected Wired connection 2 enp0s3 ethernet connected Wired connection 1 lo loopback unmanaged --
5) Bringing UP/Down a Network Interface using nmtui tool?
nmtui is a curses based TUI application used for interacting with NetworkManager.
It allows you to easily configure your network interfaces on Linux distributions using a graphical display by launching the nmtui command from the terminal.
Run the following command to launch the nmtui interface. Select “Active a connection” and hit “OK”
# nmtui
Select the interface which is required to bring down and then hit “Deactivate” button.
For activation, please perform the same procedure as above.