在 Linux 中重启网卡可以通过以下几种方法进行:
方法一:使用 `ifconfig` 命令
1. 禁用网卡:
```bash
sudo ifconfig eth0 down
```
这里的 `eth0` 是网卡的名称,实际名称可能不同(例如 `ens33`、`wlan0` 等)。
2. 启用网卡:
```bash
sudo ifconfig eth0 up
```
方法二:使用 `ip` 命令
1. 禁用网卡:
```bash
sudo ip link set eth0 down
```
2. 启用网卡:
```bash
sudo ip link set eth0 up
```
方法三:使用 `systemctl` 命令(适用于基于 systemd 的系统)
1. 重启网卡服务:
```bash
sudo systemctl restart NetworkManager
```
或者:
```bash
sudo systemctl restart network
```
方法四:使用 `nmcli` 命令(NetworkManager)
1. 禁用网卡:
```bash
sudo nmcli device disconnect eth0
```
2. 启用网卡:
```bash
sudo nmcli device connect eth0
```
注意:`eth0` 是网卡的名称,你需要根据实际网卡的名称来替换它。如果你不确定网卡的名称,可以使用 `ip link` 或 `ifconfig` 命令来查看。