基本命令
# 添加默认路由
sudo route add -net 0.0.0.0 192.168.191.1
# 删除默认路由
sudo route -n delete default 192.168.191.1
# 获取默认路由
sudo route get 0.0.0.0
# 添加普通路由
sudo route -n add -net 10.1.0.0/16 192.168.0.1
# 删除普通路由
sudo route delete -net 10.1.0.0/16 192.168.0.1
# 查看路由表
netstat -rn
永久路由
- 查看网卡
networksetup -listallnetworkservices
- 查看网卡配置的路由
networksetup -getadditionalroutes [网卡]
- networksetup -setadditionalroutes [网卡] [目标IP] [掩码] [网关IP]
networksetup -setadditionalroutes ethernet 10.1.0.0 255.255.0.0 172.168.0.1
- 多条路由同时配置
networksetup -setadditionalroutes ethernet 10.1.0.0 255.255.0.0 172.168.0.1 10.2.0.0 255.255.0.0 192.168.1.1