Docker中的centos容器配置静态IP
查看当前网卡配置ifconfig
系统返回网卡配置信息
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.10 netmask 255.255.255.0 broadcast 192.168.3.10
ether 00:16:3c:cd:e5:47 txqueuelen 1000 (Ethernet)
RX packets 492680 bytes 255028104 (243.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 155333 bytes 266652071 (254.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看网卡配置文件cd /etc/sysconfig/network-scripts/
系统返回信息
[root@ network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-post ifdown-Team ifup-aliases ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifcfg-lo ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-isdn ifup-ppp ifup-TeamPort network-functions
ifdown ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifdown-bnep ifdown-isdn ifdown-sit ifup ifup-ippp ifup-plusb ifup-sit ifup-wireless
修改IP配置文件vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by SolusVM
DEVICE=eth0
BOOTPROTO=static #分为Static(静态地址)dhcp(动态地址)
ONBOOT=yes
IPADDR=192.168.3.15 #IP地址
GATEWAY=192.168.3.1 #网关
NETMASK=255.255.255.0 #子网掩码
移动光标到IP地址的位置按`I`键修改。
修改完成后按`Esc`退出编辑模式。
接着输入 `:wq` 保存设置信息。
service network restart
重载网络配置后即生效
如果安装了宝塔面板可以使用软件商店中的Linux工具箱