大网数据广告活动
服务器运维问答

How to setup OpenVPN server to work like a proxy

· 52CE 我爱测

I'm trying to setup openvpn on Amazon EC2. To check it I'm using http://whatismyipaddress.com . Currently I can connect to my remote server with: sudo openvpn --config /etc/openvpn/openvpnuser1.conf After connection the server lo…

问题原文

原帖链接 · Silk0vsky · CC BY-SA 3.0

I'm trying to setup openvpn on Amazon EC2. To check it I'm using http://whatismyipaddress.com.

Currently I can connect to my remote server with:

sudo openvpn --config /etc/openvpn/openvpnuser1.conf

After connection the server log has:

Sun Jun 11 08:44:06 2017 us=235368 GET INST BY REAL: 176.XX.193.73:54967 [succeeded]
Sun Jun 11 08:44:06 2017 us=235386 user1/176.XX.193.73:54967 UDPv4 READ [69] from [AF_INET]176.XX.193.73:54967: P_DATA_V1 kid=0 DATA 117650fd 4f53ac24 d1614c31 f40cd5d1 49c86aa0 066fc87e 7e1db1fb 47321f9[more...]
Sun Jun 11 08:44:06 2017 us=235393 user1/176.XX.193.73:54967 TLS: tls_pre_decrypt, key_id=0, IP=[AF_INET]176.XX.193.73:54967
Sun Jun 11 08:44:06 2017 us=235405 user1/176.XX.193.73:54967 DECRYPT IV: 066fc87e 7e1db1fb 47321f94 d4f764ee
Sun Jun 11 08:44:06 2017 us=235416 user1/176.XX.193.73:54967 DECRYPT TO: 00000008 fa2a187b f3641eb4 cb07ed2d 0a981fc7 48
Sun Jun 11 08:44:06 2017 us=235425 user1/176.XX.193.73:54967 PID_TEST [0] [SSL-0] [>EEEEEE] 0:7 0:8 t=1497170646[0] r=[0,64,15,0,1] sl=[57,7,64,528]
Sun Jun 11 08:44:06 2017 us=235431 user1/176.XX.193.73:54967 RECEIVED PING PACKET
Sun Jun 11 08:44:06 2017 us=235437 PO_CTL rwflags=0x0001 ev=4 arg=0x55687fb01180
Sun Jun 11 08:44:06 2017 us=235441 PO_CTL rwflags=0x0001 ev=5 arg=0x55687fb01068
Sun Jun 11 08:44:06 2017 us=235448 I/O WAIT TR|Tw|SR|Sw [8/142628]

Also the client raised additional interface & gained IP address (ifconfig):

tun1      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.0.0.6  P-t-P:10.0.0.5  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

So, I assume that openvpn connection has been established. But unfortunately the http://whatismyipaddress.com still shows my (client) real IP add.


Client config:

client
dev tun
proto udp
remote 52.XX.48.224 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/user1.crt
key /etc/openvpn/user1.key
tls-auth /etc/openvpn/ccd/ta.key 1
cipher AES-256-CBC
ns-cert-type server
comp-lzo
log /var/log/openvpn.log
verb 3
sndbuf 0
rcvbuf 0

Server config:

port 1194
proto udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/ServerV1.crt
key /etc/openvpn/ServerV1.key
dh /etc/openvpn/dh2048.pem
tls-auth /etc/openvpn/ccd/ta.key 0
cipher AES-256-CBC
server 10.0.0.0 255.255.255.0
keepalive 10 120
persist-key
persist-tun
client-config-dir /etc/openvpn/ccd
status ServerV1-status.log
log /var/log/ServerV1.log
sndbuf 0
rcvbuf 0
push "redirect-geteway def1"
push "dhcp-options DNS 8.8.8.8"
comp-lzo
verb 15

Server forwarding enabled

cat /proc/sys/net/ipv4/conf/all/forwarding
1

iptables edited with:

iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth1 -j MASQUERADE
iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  ip-10-0-0-0.eu-central-1.compute.internal/24  anywhere

已采纳解答

原帖链接 · Pablo · CC BY-SA 3.0

It seems you have a typo in your server config:

    push "redirect-geteway def1"

should be

    push "redirect-gateway def1"

and that could very much be the reason the client is not setting a default route through the tunnel once it is established.

Hope it helps!

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。