Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to test linux network namespace.

The current problem is I cannot connect internet in the namespace

here is my commands:

1 Create network namespace netns1, create a pair of veths (A and B) set B into namespace

ip netns add netns1
ip link add A type veth peer name B
ip link set B netns netns1

2 create a bridge to connect veth A

brctl addbr bridge0
ip addr add 172.17.42.1/16 dev bridge0
ip link set dev bridge0 up
brctl addif bridge0 A
ip link set A up

3 In namespace, set the network

ip netns exec netns1 ip link set dev B name eth0
ip netns exec netns1 ip link set eth0 up
ip netns exec netns1 ip addr add 172.17.42.99/16 dev eth0
ip netns exec netns1 ip route add default via 172.17.42.1

When I ping google, I got this:

ping: unknown host www.google.com

How can I connect to the internet in this namespace ?

Here are some other details:

enter image description here

enter image description here

enter image description here

enter image description here

Thank you

update 1

I also try to set the NAT:

iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -d 0.0.0.0/0 -j MASQUERADE

But still unknown host

share|improve this question

1 Answer 1

I'm assuming you are getting ping: unknown host www.google.com because your name resolution if failing because of the network connectivity issues mentioned below. However, you probably want to double check that this isn't just a DNS issue by pinging an IP address.

From what you've provided, it looks like you haven't added a physical interface to the network bridge. Without a physical interface on the bridge, traffic on that bridge has no way onto the rest of the network.

An alternative to adding a physical interface to the bridge, would be to turn on IP forwarding and set up NAT rules with iptables.

share|improve this answer
    
Thank you, i am trying to set NAT rules, it would be great if you can provide more details about this. –  vvilp Sep 22 '14 at 22:55
    
I try like this: iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -d 0.0.0.0/0 -j MASQUERADE But still unknown host –  vvilp Sep 22 '14 at 23:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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