linux下查找默认网关网卡及IP的命令
WANNIC=`netstat -nr 2>/dev/null | grep -v ppp | grep -v tun | grep -v vpn |awk '$1 == "0.0.0.0" && $3 == "0.0.0.0" {print $NF}'`
0.0.0.0 192.168.1.118 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 venet0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 tun0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 cscotun0
0.0.0.0 192.168.30.1 0.0.0.0 UG 0 0 0 vpn_se
venet0: flags=211<UP,BROADCAST,POINTOPOINT,RUNNING,NOARP> mtu 1500
inet 127.0.0.1 netmask 255.255.255.255 broadcast 0.0.0.0 destination 127.0.0.1
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 0 (UNSPEC)
RX packets 41679 bytes 9284392 (8.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28948 bytes 1966742 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
venet0:0: flags=211<UP,BROADCAST,POINTOPOINT,RUNNING,NOARP> mtu 1500
inet 123.132.111.144 netmask 255.255.255.255 broadcast 123.132.111.144 destination 123.132.111.144
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 0 (UNSPEC)
WANIP=`ip route get 1.2.3.4 dev "$WANNIC" 2>/dev/null | head -1 | awk '{print $NF}'`
[ 本帖最后由 linda 于 2017-5-31 11:47 编辑 ]
搜索更多相关主题的帖子:
linux