Reference: https://www.tecmint.com/ip-command-examples/
Learn the configuration IP of Linux, configure the gateway, add routes and other commands
man ipman ip addressman ip routeip address help可简写ip a s
Operations & Viewing interfaces
- 查看所有接口ip+macip a- 查看eth0的ip+macip a s eth0- 给一个接口设置多个ip(ip addr add)ip a a 12.1.1.1/24 dev eth0ip a a 13.1.1.1/24 dev eth0- 删除一个接口的ipip a d 13.1.1.1/24 dev eth0- 持久化配置到文件(wr)ip address save 1> b.txtip address restore < b.txt## 开关接口(shu/no shu) ip link set eth0 up ip link set eth0 down
Operation Routing
- 查看arp表和路由表ip neiip r参考: https://serverfault.com/questions/63014/ip-address-scope-parameter/63018scope SCOPE_VALUE global - the address is globally valid.(大多数是这样的) link - the address is link local, i.e. it is valid only on this device.(如一个子网的广播地址) host - the address is valid only inside this host. (127.0.0.1)- 添加默认路由ip route add default via 192.168.1.1 dev eth0- 指定下一跳ip route add 30.1.1.0/24 via 15.1.1.1- 指定下一跳和出接口ip route add 30.1.1.0/24 via 15.1.1.1 dev eth0 - 检测某个目的ip从哪个口出去$ ip route get 172.17.0.2172.17.0.2 dev docker0 src 172.17.0.1 $ ip route get 8.8.8.88.8.8.8 via 192.168.14.2 dev eth0 src 192.168.14.133
Command comparison
Reference
Reference: https://linux.cn/article-3144-1.html
[Svc]linux's IP command operation interface and routing table