ip link set ns1-vnic name eth0
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 92:69:39:f3:b3:be
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
LOOPBACK MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
刚才把默认的名字修改为了eth0,下面我们给他分配一个private ip address:
ip addr add 10.0.0.100/24 dev eth0
然后把它启动起来:
ip link set eth0 up
# ifconfig
eth0 Link encap:Ethernet HWaddr 92:69:39:f3:b3:be
inet addr:10.0.0.100 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
然后我们再把回环起起来,ping一下自己感受一下:
# ip link set lo up
root@ubuntu:~# ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_req=1 ttl=64 time=0.072 ms
64 bytes from 10.0.0.100: icmp_req=2 ttl=64 time=0.040 ms
~# ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_req=1 ttl=64 time=0.200 ms
64 bytes from 10.0.0.100: icmp_req=2 ttl=64 time=0.042 ms
嗷嗷!又通了!
我们进入ns1往10.0.0.1来ping一下:
~# ip netns exec ns1 ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_req=1 ttl=64 time=0.057 ms
64 bytes from 10.0.0.1: icmp_req=2 ttl=64 time=0.063 ms