I've finally set up the netns veth openvpn connection that works, made overrides to systemd service files so openvpn depended on netns single shot service and tor of openvpn service. Tor works, at least by its logs it is, but I can't access it. My current netns-vpn.service
file is:
# netns
ExecStartPre=-ip netns delete openvpn
ExecStartPre= ip netns add openvpn
# links
ExecStartPre=ip link add vpn0 type veth peer name vpn1
ExecStartPre=ip link set vpn1 netns openvpn
# set links and localhost for vpn
ExecStartPre=ip link set dev vpn0 up
ExecStartPre=ip -n openvpn link set dev lo up
ExecStartPre=ip -n openvpn link set dev vpn1 up
# assign ips to them, and loop traffic from vpn1 to vpn0
ExecStartPre=ip addr add 10.0.0.0/24 dev vpn0
ExecStartPre=ip -n openvpn addr add 10.0.0.1/24 dev vpn1
ExecStartPre=ip -n openvpn route add default via 10.0.0.0
# port forwarding
ExecStartPre=iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 9049 -j DNAT --to-destination 10.0.0.1:9049
ExecStartPre=iptables -t nat -A PREROUTING -p udp -i eth0 --dport 9049 -j DNAT --to-destination 10.0.0.1:9049
ExecStartPre=iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 9049 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
ExecStartPre=iptables -A FORWARD -p udp -d 10.0.0.1 --dport 9049 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# packet forwarding from eth0 to vpn0 and back
ExecStartPre=iptables -A FORWARD -i eth0 -o vpn0 -j ACCEPT
ExecStartPre=iptables -A FORWARD -o eth0 -i vpn0 -j ACCEPT
# idk
ExecStartPre=iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
the port forwarding part doesn't work for socks5 proxy. From what I gathered I need to use filters or -A OUTPUT
, but I can't find an example with network namespaces and socks5 proxy to make sense of it. It's all new to me. Tcp forwarding works, tested it with python http.server, I guess udp should too.
I'm not looking for socat
or any other proxy across namespaces solution.