多网卡下如何配置指定IP走某个路由器(适用于外网不通,但是钉钉服务器通的情况)

# 多网卡下如何配置指定IP走某个路由器(适用于外网不通,但是钉钉服务器通的情况)

## 如何查看一个进程建立的网络连接,方式一

- 查看进程pid `ps -ef|grep dingtalk`
- 查看进程的连接 `lsof -p pid -nP|grep TCP`
```
$ lsof -p 9542,9583,9587,9531 -nP |grep TCP
dingtalk 9531 lixu  110u     sock                0,9      0t0 282904864 protocol: TCP
dingtalk 9531 lixu  145u     IPv4          282864365      0t0       TCP 192.168.43.110:38536->203.119.215.179:443 (ESTABLISHED)
dingtalk 9531 lixu  151u     sock                0,9      0t0 282904865 protocol: TCP
```

## 如何查看一个进程建立的网络连接,方式二
- 查看进程的连接 `netstat -antlp|grep dingtalk`
```
$ netstat -antlp|grep dingtalk
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp       32      0 192.168.43.110:44560    106.11.208.166:443      CLOSE_WAIT  9531/dingtalk       
tcp       32      0 192.168.43.110:44562    106.11.208.166:443      CLOSE_WAIT  9531/dingtalk       
tcp        0      0 192.168.43.110:38536    203.119.215.179:443     ESTABLISHED 9531/dingtalk
```


## 钉钉的服务器地址

tcp        0     90 192.168.60.26:60006     203.119.215.179:443     ESTABLISHED 4777/dingtalk   
tcp        0      0 192.168.43.110:52588    203.119.215.179:443     ESTABLISHED 4777/dingtalk     


## 钉钉服务器加入到静态路由表

```
sudo route add -host 203.119.201.180 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.206.75 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.206.251 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.207.121 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.207.122 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.211.253 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.214.249 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.214.251 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.215.179 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 203.119.216.175 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 111.6.226.253 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 111.7.187.240 gw 192.168.60.1 dev enp0s31f6
sudo route add -host 111.7.187.241 gw 192.168.60.1 dev enp0s31f6
```

## 删除路由

```
sudo route del -host 203.119.201.180
sudo route del -host 203.119.206.75
sudo route del -host 203.119.206.251
sudo route del -host 203.119.207.121
sudo route del -host 203.119.207.122
sudo route del -host 203.119.211.253
sudo route del -host 203.119.214.249
sudo route del -host 203.119.214.251
sudo route del -host 203.119.215.179
sudo route del -host 203.119.216.175
sudo route del -host 111.6.226.253
sudo route del -host 111.7.187.240
sudo route del -host 111.7.187.241
```


## 资料

- [配置Linux实现静态路由](https://www.cnblogs.com/ssgeek/p/9220690.html)
- [Linux route指定静态路由配置](https://blog.51cto.com/13447608/2088853)



 

选项and参数:

选项

解释英文

解释中文

-A

   

-c

operate on the kernel’s routing cache.

打印将Linux核心的路由缓存

-n

 

不执行DNS反向查找,直接显示数字形式的IP地址

-e

 

以netstat格式显示路由表

-net

the target is a network

到一个网络的路由表

-host

the target is a host.

到一个主机的路由表

参数

解释英文

解释中文

add

add a   new route.

增加指定的路由记录

del

delete   a route.

删除指定的路由记录

Target

 

母的网络或目的主机

gw

 

设置网关,必须可达

dev

 

路由记录所表示的网络接口

reject

 

关闭的路由

 

posted @ 2019-05-08 10:57  jiftle  阅读(1888)  评论(0编辑  收藏  举报