0

I've followed this guide to setup a network namespace (to run VPN in). Here's my setup script:

ip netns add myns
ip link add type veth
ip link set veth1 netns myns

ip addr add 10.255.255.1/24 dev veth0
ip link set dev veth0 up
ip netns exec myns ip addr add 10.255.255.2/24 dev veth1
ip netns exec myns ip link set dev veth1 up
ip netns exec myns ip ro add default via 10.255.255.1

iptables -A POSTROUTING -t nat -o wlp58s0 -s 10.255.255.2 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1

ip netns exec myns bash

Some applications bind to ports on localhost and this doesn't work.
localhost resolves to 127.0.0.1 but pings to it fail.

Can I somehow expose localhost to the network namespace?

1

In my experience, the loopback interface in the new network namespace is not brought up automatically. Check to see if it is up (example, use ip addr show in the new network namespace). If it is not up you can bring it up with something like ip netns exec myns ip link set dev lo up.

Maybe my answer should be a comment, but I don't have enough reputation to add a comment to your question.

Edit: Just for clarification, this answer shows how to activate the loopback interface in the new network namespace ("myns" in the case of the question). The default network namespace and the new network namespace each have their own loopback interface. This answer does not show how to expose the loopback interface from the default network namespace into the new network namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.