Home > Article > Operation and Maintenance > How to turn off the network card in linux
Method: 1. Use the ifconfig command to turn off the network card, the syntax is "ifconfig network card name down"; 2. Use the ifdown command to turn off the network card, the syntax is "ifdown network card name"; 3. Use the ip command to turn off the network card, the syntax For "ip link set network card name down"
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
How to turn off the network card in Linux
You may execute the following commands according to your needs. I'll list some examples here of where you might use these commands.
When you add a network card or create a virtual network card from a physical network card, you may need to use these commands to enable the new network card. In addition, if you have made some modifications to the network card or the network card itself is not enabled, then you also need to use one of the following commands to enable the network card.
There are many ways to enable and disable the network card. In this article, we’ll go over the top 5 methods we’ve used.
Enabling and disabling the network card can be accomplished using the following 5 methods:
ifconfig command: used to configure the network card. It can provide a lot of information about the network card.
ifdown/up command: ifdown command is used to disable the network card, and ifup command is used to enable the network card.
ip command: used to manage network cards, replacing the old and deprecated ifconfig command. It is very similar to the ifconfig command, but provides many powerful features that the ifconfig command does not have.
nmcli command: is a command line tool that controls NetworkManager and reports network status.
nmtui command: It is a terminal UI application based on the curses graphics library that interacts with NetworkManager.
The following shows the information about the network cards available in my Linux system.
# ip a 1: lo: 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: 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: 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. How to use the ifconfig command to enable or disable the network card?
The ifconfig command is used to configure the network card.
If you need to enable the network card during system startup, the command to call is ifconfig. ifconfig can provide a lot of network card information. No matter what configuration we want to modify the network card, we can use this command.
Common syntax of ifconfig:
# ifconfig [NIC_NAME] Down/Up
Execute the following command to disable the enp0s3 network card. Note that you need to enter your own network card name here.
# ifconfig enp0s3 down
You can see from the following output that the network card has been disabled.
# ip a | grep -A 1 "enp0s3:" 2: enp0s3: 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
Execute the following command to enable the enp0s3 network card.
# ifconfig enp0s3 up
You can see from the following output that the network card has been enabled.
# ip a | grep -A 5 "enp0s3:" 2: enp0s3: 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 use the ifdown/up command to enable or disable the network card?
The ifdown command is used to disable the network card, and the ifup command is used to enable the network card.
Note: These two commands do not support new network devices named enpXXX.
Common syntax for ifdown/ifup:
# ifdown [NIC_NAME] # ifup [NIC_NAME]
Execute the following command to disable the eth1 network card.
# ifdown eth1
You can see from the following output that the network card has been disabled.
# ip a | grep -A 3 "eth1:" 3: eth1: mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 08:00:27:d5:a0:18 brd ff:ff:ff:ff:ff:ff
Execute the following command to enable the eth1 network card.
# ifup eth1
You can see from the following output that the network card has been enabled.
# ip a | grep -A 5 "eth1:" 3: eth1: 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 do not support network cards named enpXXX. When executing this command, the results obtained are as follows:
# ifdown enp0s8 Unknown interface enp0s8
3. How to use the ip command to enable or disable the network card?
The ip command is used to manage network cards and replaces the old and deprecated ifconfig command.
It is very similar to the ifconfig command, but provides many powerful features that the ifconfig command does not have.
Common syntax for ip:
# ip link set Down/Up
Execute the following command to disable the enp0s3 network card.
# ip link set enp0s3 down
You can see from the following output that the network card has been disabled.
# ip a | grep -A 1 "enp0s3:" 2: enp0s3: 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
Execute the following command to enable the enp0s3 network card.
# ip link set enp0s3 up
You can see from the following output that the network card has been enabled.
# ip a | grep -A 5 "enp0s3:" 2: enp0s3: 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 use nmcli command to enable or disable the network card?
nmcli is a command line tool that controls NetworkManager and reports network status.
nmcli can be used as a replacement for nm-applet or other graphical clients. It can be used to display, create, modify, delete, enable and deactivate network connections. In addition to this, it can also be used to manage and display network device status.
nmcli commands work in most cases using "configuration name" instead of "device name". Therefore, execute the following command to obtain the configuration name corresponding to the network card. (LCTT Translation: When using nmtui or nmcli to manage network connections, you can configure a name for the network connection, which is the configuration name Profile name mentioned here)
# 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
Execute the following command to disable the enp0s3 network card. When disabling a network card, you need to use the configuration name rather than the device name.
# nmcli con down 'Wired connection 1' Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
You can see from the following output that the network card has been disabled.
# nmcli dev status DEVICE TYPE STATE CONNECTION enp0s8 ethernet connected Wired connection 2 enp0s3 ethernet disconnected -- lo loopback unmanaged --
Execute the following command to enable the enp0s3 network card. Again, here you need to use the configuration name instead of the device name.
# nmcli con up 'Wired connection 1' Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
You can see from the following output that the network card has been enabled.
# nmcli dev status DEVICE TYPE STATE CONNECTION enp0s8 ethernet connected Wired connection 2 enp0s3 ethernet connected Wired connection 1 lo loopback unmanaged --
5. How to use the nmtui command to enable or disable the network card?
nmtui 是一个与 NetworkManager 交互的、基于 curses 图形库的终端 UI 应用。
在启用 nmtui 的时候,如果第一个参数没有特别指定,它会引导用户选择对应的操作去执行。
执行以下命令打开 mntui 界面。选择 “Active a connection” 然后点击 “OK”。
# nmtui
相关推荐:《Linux视频教程》
The above is the detailed content of How to turn off the network card in linux. For more information, please follow other related articles on the PHP Chinese website!