本帖最後由 角色 於 2013-12-8 10:37 編輯
How to set up for client using random port number for connection?
1. We have to using port redirection to the standard UDP/TCP port 1194- iptables -t nat -A PREROUTING -p udp --match multiport --dport 10000:40000 -j DNAT --to ip.add.re.ss:1194
- iptables -t nat -A PREROUTING -p tcp --match multiport --dport 10000:40000 -j DNAT --to ip.add.re.ss:1194
複製代碼 2. For the server side, a stand configuration is used. In the following script, the server uses TCP 1194 port for connection.- local ip.add.re.ss
- port 1194
- proto tcp
- dev tun
- ca keys/ca.crt
- cert keys/server.crt
- key keys/server.key
- dh keys/dh1024.pem
- server 10.10.0.0 255.255.255.0
- ifconfig-pool-persist ipptcp.txt
- push "redirect-gateway def1 bypass-dhcp"
- push "dhcp-option DNS 208.67.222.222"
- push "dhcp-option DNS 208.67.220.220"
- keepalive 5 30
- comp-lzo
- persist-key
- persist-tun
- status tcp-server-tcp.log
- verb 3
- log /var/log/openvpn-tcp.log
- tls-auth keys/ta.key 0
- link-mtu 1400
複製代碼 3. Client side uses the option "remote-random" to set a random port for connection. If the server accepts, then the connection is established otherwise another port number is employed. If the connection is lost then another connection using another port will be tried to establish.- client
- dev tun
- proto tcp-client
- remote-random
- remote ip.add.re.ss 1194
- resolv-retry infinite
- nobind
- persist-key
- persist-tun
- ca ca.crt
- cert client1.crt
- key client1.key
- tls-auth ta.key 1
- ns-cert-type server
- comp-lzo
- verb 3
- keepalive 10 120
- route-method exe
- route-delay 2
- register-dns
- link-mtu 1400
複製代碼 4. On rotuer's iptables side, we should add- # Allow packets from the new subnet to make it out to the Internet
- iptables -A FORWARD -s 10.10.0.0/24 -j ACCEPT
- # Change the source address on outgoing packets from the new subnet to be the VPS's IP address
- iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -j SNAT --to-source ip.add.re.ss
- # Accept incoming packets on the TCP port 1194 - change this to your actual OpenVPN port
- iptables -A INPUT -p tcp --dport 1194 -j ACCEPT
複製代碼 |