mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-04 22:00:34 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
0818d34cc4
@ -7,32 +7,28 @@
|
||||
[#]: via: (https://www.2daygeek.com/enable-disable-up-down-nic-network-interface-port-linux-using-ifconfig-ifdown-ifup-ip-nmcli-nmtui/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
How To Enable (UP) And Disable (DOWN) A Network Interface Port (NIC) In Linux?
|
||||
Linux 中如何启用禁用网口?
|
||||
======
|
||||
|
||||
You may need to run these commands based on your requirements.
|
||||
你可能会根据你的需要执行以下命令。
|
||||
|
||||
I can tell you few examples, where you would be needed this.
|
||||
列举一些你会用到这些命令的例子。
|
||||
|
||||
When you add a new network interface or when you create a new virtual network interface from the original physical interface.
|
||||
当你添加一个网卡或者从一个物理网口创建出一个虚拟网口的时候,你可能需要使用这些命令将新网口启用起来。另外,如果你对网口做了某些修改或者网口本身没有启用,那么你也需要使用以下的某个命令将网口启用起来。
|
||||
|
||||
you may need to bounce these commands to bring up the new interface.
|
||||
启用禁用网口有很多种方法。在这篇文章里,我们会介绍我们使用过的、最好的 5 种方法。
|
||||
|
||||
Also, if you made any changes or if it’s down then you need to run one of the below commands to bring them up.
|
||||
启用禁用网口可以使用以下 5 个方法来完成:
|
||||
|
||||
It can be done on many ways and we would like to add best five method which we used in the article.
|
||||
|
||||
It can be done using the below five methods.
|
||||
|
||||
* **`ifconfig Command:`** The ifconfig command is used configure a network interface. It provides so many information about NIC.
|
||||
* **`ifdown/up Command:`** The ifdown command take a network interface down and the ifup command bring a network interface up.
|
||||
* **`ip Command:`** ip command is used to manage NIC. It’s replacement of old and deprecated ifconfig command. It’s similar to ifconfig command but has many powerful features which isn’t available in 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.
|
||||
* **`ifconfig 命令:`** ifconfig 命令用于配置网口。 它可以提供网口的很多信息。
|
||||
* **`ifdown/up 命令:`** ifdown 命令用于禁用网口,ifup 命令用于启用网口。
|
||||
* **`ip 命令:`** ip 命令用于管理网口,用于替代老旧的、不推荐使用的 ifconfig 命令。它和 ifconfig 命令很相似,但是提供了很多 ifconfig 命令不具有的强大的特性。
|
||||
* **`nmcli 命令:`** nmcli 是一个控制 NetworkManager 并报告网络状态的命令行工具。
|
||||
* **`nmtui 命令:`** nmtui 是一个与 NetworkManager 交互的、基于 curses 图形库的终端 UI 应用。
|
||||
|
||||
|
||||
|
||||
The below output shows the available network interface card (NIC) information in my Linux system.
|
||||
以下显示的是我的 Linux 系统中可用网口的信息。
|
||||
|
||||
```
|
||||
# ip a
|
||||
@ -56,25 +52,24 @@ The below output shows the available network interface card (NIC) information in
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
### 1) How To Bring UP And Bring Down A Network Interface In Linux Using ifconfig Command?
|
||||
### 1、如何使用 ifconfig 命令启用禁用网口?
|
||||
|
||||
The ifconfig command is used configure a network interface.
|
||||
ifconfig 命令用于配置网口。
|
||||
|
||||
It is used at boot time to set up interfaces as necessary. It provides so many information about NIC. We can use ifconfig command when we need to make any changes on NIC.
|
||||
系统启动过程中如果需要启用网口,调用的命令就是 ifconfig。 ifconfig 可以提供很多网口的信息。不管我们想修改网口的什么配置,都可以使用该命令。
|
||||
|
||||
Common Syntax for ifconfig:
|
||||
ifconfig 的常用语法:
|
||||
|
||||
```
|
||||
# ifconfig [NIC_NAME] Down/Up
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux. Make a note, you have to input your interface name instead of us.
|
||||
|
||||
执行以下命令禁用 `enp0s3` 网口。注意,这里你需要输入你自己的网口名字。
|
||||
```
|
||||
# ifconfig enp0s3 down
|
||||
```
|
||||
|
||||
Yes, the given interface is down now as per the following output.
|
||||
从以下输出结果可以看到网口已经被禁用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 1 "enp0s3:"
|
||||
@ -82,13 +77,13 @@ Yes, the given interface is down now as per the following output.
|
||||
link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux.
|
||||
执行以下命令启用 `enp0s3` 网口。
|
||||
|
||||
```
|
||||
# ifconfig enp0s3 up
|
||||
```
|
||||
|
||||
Yes, the given interface is up now as per the following output.
|
||||
从以下输出结果可以看到网口已经启用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 5 "enp0s3:"
|
||||
@ -100,13 +95,13 @@ Yes, the given interface is up now as per the following output.
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
### 2) How To Enable And Disable A Network Interface In Linux Using ifdown/up Command?
|
||||
### 2、如何使用 ifdown/up 命令启用禁用网口?
|
||||
|
||||
The ifdown command take a network interface down and the ifup command bring a network interface up.
|
||||
ifdown 命令用于禁用网口,ifup 命令用于启用网口。
|
||||
|
||||
**Note:**It doesn’t work on new interface device name like `enpXXX`
|
||||
**注意:** 这两个命令不支持以 `enpXXX` 命名的新的网络设备。
|
||||
|
||||
Common Syntax for ifdown/ifup:
|
||||
ifdown/ifup 的常用语法:
|
||||
|
||||
```
|
||||
# ifdown [NIC_NAME]
|
||||
@ -114,13 +109,13 @@ Common Syntax for ifdown/ifup:
|
||||
# ifup [NIC_NAME]
|
||||
```
|
||||
|
||||
Run the following command to bring down the `eth1` interface in Linux.
|
||||
执行以下命令禁用 `eth1` 网口。
|
||||
|
||||
```
|
||||
# ifdown eth0
|
||||
# ifdown eth1
|
||||
```
|
||||
|
||||
Run the following command to bring down the `eth1` interface in Linux.
|
||||
从以下输出结果可以看到网口已经被禁用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 3 "eth1:"
|
||||
@ -128,13 +123,13 @@ Run the following command to bring down the `eth1` interface in Linux.
|
||||
link/ether 08:00:27:d5:a0:18 brd ff:ff:ff:ff:ff:ff
|
||||
```
|
||||
|
||||
Run the following command to bring down the `eth1` interface in Linux.
|
||||
执行以下命令启用 `eth1` 网口。
|
||||
|
||||
```
|
||||
# ifup eth0
|
||||
# ifup eth1
|
||||
```
|
||||
|
||||
Yes, the given interface is up now as per the following output.
|
||||
从以下输出结果可以看到网口已经启用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 5 "eth1:"
|
||||
@ -145,32 +140,32 @@ Yes, the given interface is up now as per the following output.
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
ifup and ifdown doesn’t supporting the latest interface device `enpXXX` names. I got the below message when i ran the command.
|
||||
ifup 和 ifdown 不支持以 `enpXXX` 命名的网口。当执行该命令时得到的结果如下:
|
||||
|
||||
```
|
||||
# ifdown enp0s8
|
||||
Unknown interface enp0s8
|
||||
```
|
||||
|
||||
### 3) How To Bring UP/Bring Down A Network Interface In Linux Using ip Command?
|
||||
### 3、如何使用 ip 命令启用禁用网口?
|
||||
|
||||
ip command is used to manage Network Interface Card (NIC). It’s replacement of old and deprecated ifconfig command on modern Linux systems.
|
||||
ip 命令用于管理网口,用于替代老旧的、不推荐使用的 ifconfig 命令。
|
||||
|
||||
It’s similar to ifconfig command but has many powerful features which isn’t available in ifconfig command.
|
||||
它和 ifconfig 命令很相似,但是提供了很多 ifconfig 命令不具有的强大的特性。
|
||||
|
||||
Common Syntax for ip:
|
||||
ip 的常用语法:
|
||||
|
||||
```
|
||||
# ip link set Down/Up
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux.
|
||||
执行以下命令禁用 `enp0s3` 网口。
|
||||
|
||||
```
|
||||
# ip link set enp0s3 down
|
||||
```
|
||||
|
||||
Yes, the given interface is down now as per the following output.
|
||||
从以下输出结果可以看到网口已经被禁用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 1 "enp0s3:"
|
||||
@ -178,13 +173,13 @@ Yes, the given interface is down now as per the following output.
|
||||
link/ether 08:00:27:c2:e4:e8 brd ff:ff:ff:ff:ff:ff
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux.
|
||||
执行以下命令启用 `enp0s3` 网口。
|
||||
|
||||
```
|
||||
# ip link set enp0s3 up
|
||||
```
|
||||
|
||||
Yes, the given interface is up now as per the following output.
|
||||
从以下输出结果可以看到网口已经启用了。
|
||||
|
||||
```
|
||||
# ip a | grep -A 5 "enp0s3:"
|
||||
@ -196,15 +191,13 @@ Yes, the given interface is up now as per the following output.
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
### 4) How To Enable And Disable A Network Interface In Linux Using nmcli Command?
|
||||
### 4、如何使用 nmcli 命令启用禁用网口?
|
||||
|
||||
nmcli is a command-line tool for controlling NetworkManager and reporting network status.
|
||||
nmcli 是一个控制 NetworkManager 并报告网络状态的命令行工具。
|
||||
|
||||
It can be utilized as a replacement for nm-applet or other graphical clients. nmcli is used to create, display, edit, delete, activate, and deactivate network
|
||||
nmcli 可以用做 nm-applet 或者其他图形化客户端的替代品。 它可以用于展示、创建、修改、删除、启用和停用网络连接。除此之后,它还可以用来管理和展示网络设备状态。
|
||||
|
||||
connections, as well as control and display network device status.
|
||||
|
||||
Run the following command to identify the interface name because nmcli command is perform most of the task using `profile name` instead of `device name`.
|
||||
nmcli 命令大部分情况下都是使用`配置名称`工作而不是`设备名称`。所以,执行以下命令,获取网口对应的配置名称。【译者注:在使用 nmtui 或者 nmcli 管理网络连接的时候,可以为网络连接配置一个名称,就是这里提到的`配置名称(Profile name)`】
|
||||
|
||||
```
|
||||
# nmcli con show
|
||||
@ -213,20 +206,20 @@ Wired connection 1 3d5afa0a-419a-3d1a-93e6-889ce9c6a18c ethernet enp0s3
|
||||
Wired connection 2 a22154b7-4cc4-3756-9d8d-da5a4318e146 ethernet enp0s8
|
||||
```
|
||||
|
||||
Common Syntax for ip:
|
||||
nmcli 的常用语法:
|
||||
|
||||
```
|
||||
# nmcli con Down/Up
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux. You have to give `profile name` instead of `device name` to bring down it.
|
||||
执行以下命令禁用 `enp0s3` 网口。 在禁用网口的时候,你需要使用`配置名称`而不是`设备名称`。
|
||||
|
||||
```
|
||||
# nmcli con down 'Wired connection 1'
|
||||
Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
|
||||
```
|
||||
|
||||
Yes, the given interface is down now as per the following output.
|
||||
从以下输出结果可以看到网口已经禁用了。
|
||||
|
||||
```
|
||||
# nmcli dev status
|
||||
@ -236,14 +229,14 @@ enp0s3 ethernet disconnected --
|
||||
lo loopback unmanaged --
|
||||
```
|
||||
|
||||
Run the following command to bring down the `enp0s3` interface in Linux. You have to give `profile name` instead of `device name` to bring down it.
|
||||
执行以下命令启用 `enp0s3` 网口。 同样的,这里你需要使用`配置名称`而不是`设备名称`。
|
||||
|
||||
```
|
||||
# nmcli con up 'Wired connection 1'
|
||||
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
|
||||
```
|
||||
|
||||
Yes, the given interface is up now as per the following output.
|
||||
从以下输出结果可以看到网口已经启用了。
|
||||
|
||||
```
|
||||
# nmcli dev status
|
||||
@ -253,13 +246,13 @@ enp0s3 ethernet connected Wired connection 1
|
||||
lo loopback unmanaged --
|
||||
```
|
||||
|
||||
### 5) How To Bring UP/Bring Down A Network Interface In Linux Using nmtui Command?
|
||||
### 5、如何使用 nmtui 命令启用禁用网口?
|
||||
|
||||
nmtui is a curses based TUI application for interacting with NetworkManager.
|
||||
nmtui 是一个与 NetworkManager 交互的、基于 curses 图形库的终端 UI 应用。
|
||||
|
||||
When starting nmtui, the user is prompted to choose the activity to perform unless it was specified as the first argument.
|
||||
在启用 nmtui 的时候,如果第一个参数没有特别指定,它会引导用户选择对应的操作去执行。
|
||||
|
||||
Run the following command launch the nmtui interface. Select “Active a connection” and hit “OK”
|
||||
执行以下命令打开 mntui 界面。选择 “Active a connection” 然后点击 “OK”。
|
||||
|
||||
```
|
||||
# nmtui
|
||||
@ -267,10 +260,10 @@ Run the following command launch the nmtui interface. Select “Active a connect
|
||||
|
||||
[![][1]![][1]][2]
|
||||
|
||||
Select the interface which you want to bring down then hit “Deactivate” button.
|
||||
选择你要禁用的网口,然后点击 “Deactivate” 按钮,就可以将网口禁用。
|
||||
[![][1]![][1]][3]
|
||||
|
||||
For activation do the same above procedure.
|
||||
如果要启用网口,使用上述同样的步骤即可。
|
||||
[![][1]![][1]][4]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -279,7 +272,7 @@ via: https://www.2daygeek.com/enable-disable-up-down-nic-network-interface-port-
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[bodhix](https://github.com/bodhix)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user