我有一台带有两个 NIC 的服务器,均连接到网络:
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.1.2 netmask 255.255.255.0 broadcast 10.0.1.255
inet6 fe80::9618:82ff:fe37:9048 prefixlen 64 scopeid 0x20<link>
ether 94:18:82:37:90:48 txqueuelen 1000 (Ethernet)
RX packets 438291 bytes 66054606 (66.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1396490 bytes 1999931481 (1.9 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.1.3 netmask 255.255.255.0 broadcast 10.0.1.255
inet6 fe80::9618:82ff:fe37:9049 prefixlen 64 scopeid 0x20<link>
ether 94:18:82:37:90:49 txqueuelen 1000 (Ethernet)
RX packets 61399 bytes 7297765 (7.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3247 bytes 689114 (689.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 217840 bytes 55504285 (55.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 217840 bytes 55504285 (55.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
第一个接口 (eno1) 是默认网关。我正在尝试配置 OpenVPN 客户端以仅通过 VPN 路由来自第二个接口 (eno2) 的流量。目前我使用这个 openVPN 配置:
client
dev tun
proto udp
remote ca-toronto.privateinternetaccess.com 1198
resolv-retry infinite
persist-key
persist-tun
cipher aes-128-cbc
auth sha1
tls-client
remote-cert-tls server
auth-user-pass user.data
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.rsa.2048.pem
ca ca.rsa.2048.crt
disable-occ
log-append /var/log/piavpn.log
nobind
route-noexec
根据我的发现,我认为我需要设置 route-noexec 选项,以防止通过 VPN 路由所有流量。OpenVPN 添加了此隧道:
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.87.10.6 netmask 255.255.255.255 destination 10.87.10.5
inet6 fe80::3f6e:2346:240f:4169 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 1 bytes 44 (44.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1 bytes 48 (48.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
路线列表如下:
default via 10.0.1.1 dev eno1
10.0.1.0/24 dev eno1 proto kernel scope link src 10.0.1.2
10.0.1.0/24 dev eno2 proto kernel scope link src 10.0.1.3
10.87.10.5 dev tun0 proto kernel scope link src 10.87.10.6
我想我必须将所有流量从 eno2 路由到 tun0,但我不知道该怎么做。最后,我希望所有使用 eno2 的流量都通过 VPN,而 eno1 保持原样。