從 CentOS 7 以後的版本,要管理 Linux 網路必須改用新指令集,例如 ip、nmcli 等。
替代 ifconfig 指令
顯示所有網卡資訊
ip addr
ip a
顯示 eth0 網卡資訊
ip a show eth0
開啟/關閉網卡
ip link set eth0 { up | down }
顯示所有的網路裝置
ip link show
ip l show
設定 IP (非永久)
ip a add 192.168.1.200/255.255.255.0 dev eth0
移除 IP (非永久)
ip a del 192.168.1.200/255.255.255.0 dev eth0
顯示 default gateway 及路由表
ip route show
ip r show
ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
ip route del 10.10.20.0/24
Default gateway
ip route add default via 192.168.50.100
網路即時狀態
ip -s link
顯示 ARP 紀錄 (NOTE: 查詢連接網路設備的 MAC address 與 IP 對應表)
ip neigh show
ip n show
清除 ARP 清單裡的某個 IP 紀錄
ip -s -s n f <ip-address>
線上求助
ip a help
在多個網路埠的主機上,如何得知哪些埠有接上網路線
1. 列出所有網路埠 ip link show 如果埠號顯示 DOWN 必須先啟動 2. 啟動網路埠 NOTE: 啟動前要注意 IP 是否會衝突 ip link set eth6 up 3. 啟動後檢測線路 ethtool eth6 | grep detected
Command line tool for network management
List all of ethernet devices
nmcli con
Restart the network adapter enp0s3
nmcli con down enp0s3 && nmcli con up enp0s3
Configure the static ip
nmcli con mod enp0s3 ipv4.addresses 192.168.20.170/24 nmcli con mod enp0s3 ipv4.gateway 192.168.20.1 nmcli con mod enp0s3 ipv4.method manual nmcli con mod enp0s3 ipv4.dns "8.8.8.8" nmcli con down enp0s3 nmcli con up enp0s3
A GUI on console for network management
Start the GUI
nmtui
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |