vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6i 127.0.0.1 docker2
docker2爲主機名css
vi /etc/hostname
docker2
注意:這是修改配置文件的方式,能夠用命令行的方式修改hostnameios
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
#BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eno16777736 UUID=ca79f88e-e6ef-485f-93d9-671d4b49afaf DEVICE=eno16777736 #ONBOOT=no #static ip NM_CONTROLLED=no ONBOOT=yes BOOTPROTO=static HWADDR=00:0c:29:bf:c6:35 IPADDR=192.168.175.211 NETMASK=255.255.255.0 GATEWAY=192.168.175.2 DNS1=192.168.175.2
HWADDR爲mac地址,能夠不設置,若是要設置的話,能夠先使用ip addr
命令查看git
service network restart
,或者重啓主機reboot
cd /etc/sysconfig/network-scripts/
mv ifcfg-eno16777736 ifcfg-eth0
ifcfg-eth0
中的DEVICE=eno16777736
修改成DEVICE=eth0
,這一步很重要,不然重啓服務service network restart
會失敗報錯ifcfg-eth0
完整配置以下:TYPE=Ethernet
#BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eno16777736 UUID=ca79f88e-e6ef-485f-93d9-671d4b49afaf #DEVICE=eno16777736 #ONBOOT=no #static ip DEVICE=eth0 NM_CONTROLLED=no ONBOOT=yes BOOTPROTO=static HWADDR=00:0c:29:bf:c6:35 IPADDR=192.168.175.211 NETMASK=255.255.255.0 GATEWAY=192.168.175.2 DNS1=192.168.175.2
vi /etc/sysconfig/grub
或者vi /etc/default/grub
添加net.ifnames=0 biosdevname=0
docker
生成啓動菜單
grub2-mkconfig -o /boot/grub2/grub.cfg
centos
重啓系統生效 reboot
ruby
[root@docker2 default]# yum list|grep net-tools net-tools.x86_64 2.0-0.22.20131004git.el7 base [root@docker2 default]# yum -y install net-tools
[root@docker2 default]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.175.211 netmask 255.255.255.0 broadcast 192.168.175.255 inet6 fe80::20c:29ff:febf:c635 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:bf:c6:35 txqueuelen 1000 (Ethernet) RX packets 11686 bytes 12134729 (11.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3906 bytes 300355 (293.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0