修改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为主机名

  • vi /etc/hostname
docker2

注意:这是修改配置文件的方式,可以用命令行的方式修改hostname

配置静态的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命令查看

  • 重启服务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

     
     

     

  • 生成启动菜单
    grub2-mkconfig -o /boot/grub2/grub.cfg

  • 重启系统生效 reboot

在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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

版权声明:本文为adolfmc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/adolfmc/p/9195375.html