configure net namespace on ubuntu 12.04
来源:互联网 发布:淘宝债权转让车被骗 编辑:程序博客网 时间:2024/06/13 06:56
configure net namespace on ubuntu 12.04
1. necessary tools:
VETH device
iptables
linux bridge
2. create a namespace
ip netns add fib_1
3. create veth device
ip link add name fib_1-nic type veth peer name fib_1-vnic
4. insert device to fib_1
ip link set fib_1-vnic netns fib_1
5. enter fib_1 namespace
ip netns exec fib_1 bash
modify the name to eth0 and configure ip address, and ping itself
ip link set fib_1-vnic name eth0
ip addr add 10.0.0.100/24 dev eth0
ip link set eth0 up
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
6. quit namespace
exit
7. add a linux bridge, and configure it.
brctl addbr fibbr
brctl addif fibbr fib_1-nic
ip link set fib_1-nic up
ip addr add 10.0.0.1/24 dev fibbr
ip link set fibbr up
8. test the connection to namespace
ping 10.0.0.9
PING 10.0.0.9 (10.0.0.9) 56(84) bytes of data.
64 bytes from 10.0.0.9: icmp_req=1 ttl=64 time=0.200 ms
64 bytes from 10.0.0.9: icmp_req=2 ttl=64 time=0.042 ms
ip netns exec fib_1 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
9.let the namespace can access internet
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig fibbr 128.224.162.253/24 up
route del -n 128.224.162.0/24 dev fibbr
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A POSTROUTING -s 10.0.0.0/24 -j SNAT --to-source 128.224.162.253
Then net namespace can access the world.
1. necessary tools:
VETH device
iptables
linux bridge
2. create a namespace
ip netns add fib_1
3. create veth device
ip link add name fib_1-nic type veth peer name fib_1-vnic
4. insert device to fib_1
ip link set fib_1-vnic netns fib_1
5. enter fib_1 namespace
ip netns exec fib_1 bash
modify the name to eth0 and configure ip address, and ping itself
ip link set fib_1-vnic name eth0
ip addr add 10.0.0.100/24 dev eth0
ip link set eth0 up
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
6. quit namespace
exit
7. add a linux bridge, and configure it.
brctl addbr fibbr
brctl addif fibbr fib_1-nic
ip link set fib_1-nic up
ip addr add 10.0.0.1/24 dev fibbr
ip link set fibbr up
8. test the connection to namespace
ping 10.0.0.9
PING 10.0.0.9 (10.0.0.9) 56(84) bytes of data.
64 bytes from 10.0.0.9: icmp_req=1 ttl=64 time=0.200 ms
64 bytes from 10.0.0.9: icmp_req=2 ttl=64 time=0.042 ms
ip netns exec fib_1 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
9.let the namespace can access internet
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig fibbr 128.224.162.253/24 up
route del -n 128.224.162.0/24 dev fibbr
ifconfig fibbr add 10.0.0.1/24 up
ip netns exec fib_1 route add default gw 10.0.0.1
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A POSTROUTING -s 10.0.0.0/24 -j SNAT --to-source 128.224.162.253
Then net namespace can access the world.
0 0
- configure net namespace on ubuntu 12.04
- Configure OpenVPN on Ubuntu
- ubuntu 9.04 net configure
- Howto Install and Configure VTK on Ubuntu
- Howto Install and Configure QtCreator on Ubuntu
- Howto Install and Configure PCL on Ubuntu
- Howto Install and Configure ROS on Ubuntu
- Configure openerp on ubuntu 14.x(14.10)
- Configure Always On Availability Group for SQL Server on Ubuntu
- How to configure LAMP server on Ubuntu System
- Howto Install and Configure Chinese Input Methods on Ubuntu
- Howto Install and Configure Doxygen for QtCreator on Ubuntu
- Install And Configure Nagios on Ubuntu 14.04 LTS
- How to Configure and Install ownCloud on Ubuntu 16.04
- How To Install and Configure Elasticsearch on Ubuntu 14.04
- install and configure git on Windows,Ubuntu,Mac
- Ubuntu configure
- Configure Always On Availability Group for SQL Server on Ubuntu——Ubuntu上配置SQL Server Always On Avail
- 【笨木头Cocos2dx 041】战争迷雾效果 第4章_真正的迷雾来了!
- Android No active compatible AVD's or devices found Exception
- 嵌入式Linux开发-童金浩
- 战争迷雾效果 第05章 项目源码下载
- 新手程序员最常用的十大网站
- configure net namespace on ubuntu 12.04
- 精品运维视频推荐-张庆力
- 黑马程序员—交通灯管理系统
- 黑马程序员_选择排序和冒泡排序算法
- UltraEdit+删除空行的正则表达式
- 【回溯法】工作分配问题
- ZigBee 与低功耗WiFi对比
- Linux网络服务精讲-杨良伟
- Qt:Connection Type