您的位置:首页 > 运维架构 > Linux

[svc]linux的ip命令操作接口和路由表

2017-12-18 12:19 423 查看
参考: https://www.tecmint.com/ip-command-examples/

学会linux的配置ip,配置网关,添加路由等命令

man ip
man ip address
man ip route

ip address help

可简写
ip a s

操作&查看接口

- 查看所有接口ip+mac
ip a

- 查看eth0的ip+mac
ip a s eth0

- 给一个接口设置多个ip

(ip addr add)
ip a a 12.1.1.1/24 dev eth0
ip a a 13.1.1.1/24 dev eth0

- 删除一个接口的ip
ip a d 13.1.1.1/24 dev eth0

- 持久化配置到文件(wr)
ip address save 1> b.txt
ip address restore < b.txt

## 开关接口(shu/no shu)
ip link set eth0 up
ip link set eth0 down

操作路由

- 查看arp表和路由表

ip nei
ip r

参考: https://serverfault.com/questions/63014/ip-address-scope-parameter/63018 scope 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.2
172.17.0.2 dev docker0  src 172.17.0.1

$ ip route get 8.8.8.8
8.8.8.8 via 192.168.14.2 dev eth0  src 192.168.14.133

命令对比

参考



参考: https://linux.cn/article-3144-1.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: