1

I came up with this idea to use an AWS EC2 with two ethernet interfaces for an L2TP/IPSec VPN. One interface (eth0) will be receiving L2TP/IPSec connections (and ssh connections) from clients while the other (eth1) will be acting as the primary VPN interface. The point is that I could use the eth1 interface and it's identity to browse the internet while eth0 is only used to connect to the VPN; it's never known to the public.

I have tried routing it with iptables, done some research on using the ip route and ip rule commands, and messed with the settings of xl2tpd, pppd, and IPsec. Nothing has worked properly.

I'm using this script on GitHub to setup the VPN. https://github.com/hwdsl2/setup-ipsec-vpn

1
  • is the problem solved? i have the same problem。 i used google cloud with 2 nic, the eth0 and eth1 have different gateway . is aws also like this ?
    – lstosky
    Jul 21, 2022 at 12:45

1 Answer 1

1
##Install ipsec-vpn by script normally##

##Environment## 
eth0: 111.222.333.91/29 gw 111.222.333.92
eth1: 192.168.0.1/24 gw 192.168.0.254 (default gateway)

##Solution##
// redirect input
iptables -t nat -A PREROUTING -i eth0 -d 111.222.333.91 -j DNAT --to-destination 192.168.0.1

// redirect output
echo "100 vpn" >> /etc/iproute2/rt_tables
iptables -t mangle -A OUTPUT -p udp --sport 500 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p udp --sport 4500 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p udp --sport 1701 -j MARK --set-mark 1
ip rule add fwmark 1 table vpn
ip route add default via 111.222.333.92 dev eth0 table vpn

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .