陈奇网络工作室

文档手动配置网络

云计算

创建没有网络配置的容器

[ root @ localhost~~ ] # docker run-I-t-- RM-- net=nonealpinesh

//#

打开另一个终端

显示容器id

[root@localhost ~]# docker ps -a

查找进程id

[ root @ localhost~] # docker inspect-f\& amp; quot; {.state.PID}\\& quot; 2aefc41dbdeb

9076

[root@localhost ~]# pid=9076

创建命名空间

[ root @ localhost~] # mkdir-p/var/run/net ns

[ root @ localhost~] # ln-s/proc/$ PID/ns/net/var/run/net ns/$ PID

显示网桥NIC的IP和子网掩码信息

[ root @ localhost~] # ipaddrshowdocker 0

5: docker0: NO-CARRIER,BROADCAST,MULTICAST,UP mtu 1500 qdisc noqueue state DOWN

link/ether 02:42:8e:E7:64:4 ABR dff:ff:ff:ff:ff:ff:ff

inet 172.18.0.1/16 brd 172.18.255.255 scopeglobaldocker 0

valid _ lftforeverpreferred _ lft forever

创建" veth pair "接口a和b对

[ root @ localhost~] # sudoiplinkaddatypevethpeernameb

a将接口绑定到网桥docker0

[ root @ localhost~] # sudobrctladdifdocker 0a

启用

[ root @ localhost~] # sudoiplinksetaup

将b接口放在容器的网络名称空间中

[ root @ localhost~] # sudoiplinksetbnetns $ PID

命名为eth0

[ root @ localhost~] # sudoipnetnsexec $ pidiplinksetdevbnameeth 0

打开网络接口b

[ root @ localhost~] # sudoipnetnsexec $ pidiplinkseteth0up

配置可用的桥接网段( IP )

[ root @ localhost~] # sudoipnetnsexec $ pidipaddradd 172.18.0.99/16 deveth 0

配置默认网关

[ root @ localhost~] # sudoipnetnsexec $ pidiprouteaddefaultvia 172.18.0.1

最后,返回容器并验证网卡的配置

/# ip a

1: lo: LOOPBACK,UP,lower _ up MTU 65536 qdiscnoqueuestateunknownqlen 1

link/loopback 00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid _ lftforeverpreferred _ lft forever

18: eth0@if19: BROADCAST,MULTICAST,UP,LOWER_UP,m-down MTU 1500 qdiscnoqueuestateupqlen 1000

link/ether 6e:B9:75:8e:F4:99br dff:ff:ff:ff:ff:ff:ff

inet 172.18.0.99/16 scopeglobaleth 0

valid _ lftforeverpreferred _ lft forever

/# ping baidu.com

PingBaidu.com(123.125.114.144 ) 56数据字节

64 bytes from 123.125.114.144:seq=0TTL=53 time=2.827 ms

64 bytes from 123.125.114.144:seq=1TTL=53 time=2.900 ms

^C

--- baidu.com ping statistics ---

2 packets transmitted,2 packets received,0% packet loss

round-trip min/avg/max=2.827/2.863/2.900 ms

详情请访问云服务器、域名注册、虚拟主机的问题,请访问西部数码代理商官方网站: www.chenqinet.cn

相关推荐

后台-系统设置-扩展变量-手机广告位-内容页底部广告位3