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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

See all articles