CentOS7.2網絡配置

修改hostname

  • 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

配置靜態的ip

  • 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

修改網卡名稱爲eth0

  • 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.cfgcentos

  • 重啓系統生效 rebootruby

在centos7中繼續使用ifconfig命令

  • 安裝net-tools
[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 
  • 使用ifconfig命令
[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 
做者:對方不想理你並向你拋出一個異常 連接:https://www.jianshu.com/p/1d3388c88880 來源:簡書 簡書著做權歸做者全部,任何形式的轉載都請聯繫做者得到受權並註明出處。
相關文章
相關標籤/搜索