将互联网流量从 openvpn tun0 路由到 eth0

Gun*_*nar 5 networking vpn debian openvpn iptables

我想不通。
如何让选定的 VPN 用户通过 eth0 访问互联网?所有服务器流量都通过 eth1。
eth0 只应该让 VPN 用户在选定的端口上访问互联网,没有别的。
用户通过 eth1 连接并在 tun0 中使用单独的配置获得一个 IP,这是用户 ccd 之一:

ifconfig-push 192.168.200.5 192.168.200.6
推送“重定向网关 def1”

用户配置

客户

开发屯

原始UDP

远程 192.168.0.55 1194

解决重试无限

持久键持久调谐

ca ca.crt 证书 client.crt 密钥 client.key

ns-cert 类型的服务器

tls-auth ta.key 1

comp-lzo

动词 3

服务器配置:

本地 192.168.0.55

端口 1194

原始UDP

开发屯

ca ca.crt cert server.crt 密钥 server.key

dh1024.pem

服务器 192.168.200.0 255.255.255.0

ifconfig-pool-persist ipp.txt

客户对客户

保活 10 120

tls-auth ta.key 0

comp-lzo

最大客户 10

持久键持久调谐

我当前的 IP 表规则:

#刷新所有
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

#允许所有
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

#允许环回
iptables -A INPUT -i lo -j ACCEPT

#阻止 eth0 上的所有传入并允许已建立的连接
iptables -A INPUT -i eth0 -j DROP
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

转发开启:

sysctl net.ipv4.ip_forward=1



在谷歌(https://community.openvpn.net/openvpn/wiki/BridgingAndRouting)几个小时后,我认为这是正确的方法,但它不起作用:

# 允许从 VPN 发起的流量访问“世界”
iptables -I FORWARD -i tun0 -o eth0 \ -s 192.168.200.0/24 -m conntrack --ctstate NEW -j ACCEPT

# Allow established traffic to pass back and forth
iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED \
     -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

# Masquerade traffic from VPN to "the world" -- done in the nat table
iptables -t nat -I POSTROUTING -o eth0 \
      -s 192.168.200.0/24 -j MASQUERADE
Run Code Online (Sandbox Code Playgroud)


帮助表示赞赏:)

网络图http://s27.postimg.org/7do7o8ob7/network_map.gif

Ter*_*nen 1

您还需要设置一个策略路由表,告诉 Linux 对于 VPN 用户使用 eth0 后面的默认网关。

因此,您将为源 IP 地址位于 192.168.200.0/24 的数据包创建一个新的路由表,并将该路由表的默认网关设置为 eth0 后面的默认网关。