Linux網絡管理經常使用命令:net-tools VS iproute2
Exported from workflowy!
- net-tools vs iproute2
- net-tools
- ifconfig
ifconfig命令:用於接口及地址查看和管理
- route
- netstat
- arp
- iproute2
- ip link help
- ip addr help
- ip route help
- ss
- ip neigh
- 顯示網卡接口信息
- ifconfig -a
- ifconfig 顯示已啓用的網卡信息
- ifconfig -a:顯示全部接口,包括inactive狀態的接口
- ifconfig eth0
顯示eth0接口
- ip link [show]
顯示全部鏈接的網絡接口
- ip link show dev eht0
顯示eth0接口
- 顯示網絡接口IP地址
要是有多個IP地址分配給了某個接口,iproute2就會顯示全部IP地址,而net-tools只能顯示一個IP地址
- ifconfig
- ifconfig eht0
- ip addr [show]
- ip addr show dev eth0
顯示網絡接口IPv4地址
- ip -6 addr show dev eth0
顯示網絡接口IPv6地址
- 激活或禁止網絡接口
- ifconfig eth0 up/down
- ip link set up/down eth0
- 網絡接口分配IPv4地址
注意:若是使用iproute2,你能夠將多個IP地址分配給某個接口;若是換成ifconfig,就沒法作到這點。就ifconfig而言,一個變通辦法就是使用IP別名。
- ifconfig eth0 192.168.10.10/24
- ifconfig eth0 192.168.10.10 netmask 255.255.255.0
- ip addr add 192.168.10.10/24 dev eth0
- 網絡接口刪除IPv4地址
- ifconfig eth0 0
- ip addr del 192.168.10.10/24 dev eth0
- 更改網絡接口的MAC地址
- ifconfig eth0 hw ether 08:00:27:75:2a:66
- ip link set dev eth0 address 08:00:27:75:2a:67
- 查看IP路由表
- route -n
- netstat -rn
- ip route [show]
- 添加或修改默認路由
下面這些命令能夠添加或改動內核IP路由表中的默認路由。要注意:若是使用net-tools,只要添加一個新的默認路由,就能夠實現改動默認路由這個操做。若是使用iproute2,只需使用ip route replace命令。
- route add default gw 192.168.10.1 eth0
- route del default gw 192.168.10.1 eth0
- ip route add default via 192.168.10.1 dev eth0
- ip route replace default via 192.168.10.1 dev eth0
- 添加或刪除靜態路由
- route add -net 172.14.32.0/24 gw 192.168.1.1 dev eth0
- route del -net 172.14.32.0/24
- ip route add 172.14.32.0/24 via 192.168.1.1 dev eth0
- ip route del 172.14.32.0/24

歡迎關注本站公眾號,獲取更多信息