Home Operation and Maintenance Linux Operation and Maintenance How to turn off the network card in linux

How to turn off the network card in linux

Jan 06, 2022 pm 02:37 PM
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"

How to turn off the network card in linux

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login
Copy after login

Execute the following command to enable the enp0s3 network card.

# ifconfig enp0s3 up
Copy after login

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
Copy after login
Copy after login

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]
Copy after login

Execute the following command to disable the eth1 network card.

# ifdown eth1
Copy after login

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
Copy after login

Execute the following command to enable the eth1 network card.

# ifup eth1
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

Execute the following command to disable the enp0s3 network card.

# ip link set enp0s3 down
Copy after login

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
Copy after login
Copy after login

Execute the following command to enable the enp0s3 network card.

# ip link set enp0s3 up
Copy after login

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
Copy after login
Copy after login

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
Copy after login

Common syntax for nmcli:

# nmcli con  Down/Up
Copy after login

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)
Copy after login

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     --
Copy after login

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)
Copy after login

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  --
Copy after login

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
Copy after login

相关推荐:《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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles