centos7固定IP地址

centos7固定IP地址


  • centos7的网络IP地址配置文件
/etc/sysconfig/network-scripts 
  • 先查看当前网卡名称 ifconfig
[root@localhost]# ifconfig
docker0: flags=4163  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:dff:fe04:70eb  prefixlen 64  scopeid 0x20
        ether 02:42:0d:04:70:eb  txqueuelen 0  (Ethernet)
        RX packets 667  bytes 1606039 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 997  bytes 272465 (266.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163  mtu 1500
        inet 192.168.229.175  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::e6f1:a244:8e00:5639  prefixlen 64  scopeid 0x20
        ether 00:0c:29:1f:1d:a2  txqueuelen 1000  (Ethernet)
        RX packets 1806  bytes 356013 (347.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2057  bytes 2644609 (2.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (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

veth3af3ed4: flags=4163  mtu 1500
        inet6 fe80::a4d2:2ff:fe1a:e6cd  prefixlen 64  scopeid 0x20
        ether a6:d2:02:1a:e6:cd  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23  bytes 1873 (1.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth5705b61: flags=4163  mtu 1500
        inet6 fe80::30c3:96ff:fe3c:5a0f  prefixlen 64  scopeid 0x20
        ether 32:c3:96:3c:5a:0f  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 25  bytes 2133 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethb48dd9e: flags=4163  mtu 1500
        inet6 fe80::8493:b0ff:fe99:3410  prefixlen 64  scopeid 0x20
        ether 86:93:b0:99:34:10  txqueuelen 0  (Ethernet)
        RX packets 667  bytes 1615377 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 997  bytes 272252 (265.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:04:9d:27  txqueuelen 1000  (Ethernet)
        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
  • ens33网卡对应的配置文件为ifcfg-ens33,使用vim编辑如下
[root@localhost]#  vim ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"         # 使用静态IP地址,默认为dhcp
IPADDR="192.168.241.100"   # 设置的静态IP地址
NETMASK="255.255.255.0"    # 子网掩码
GATEWAY="192.168.241.2"    # 网关地址
DNS1="192.168.241.2"       # DNS服务器
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="95b614cd-79b0-4755-b08d-99f1cca7271b"
DEVICE="ens33"
ONBOOT="yes"             #是否开机启用
  • 重启network服务实现置静态IP地址
[root@localhost]# service network restart 
[root@localhost]# systemctl restart newwork.service
  • 其他辅助

    • 查看本机网关
    [root@localhost]#  route -n
    
    Kernel IP routing table
    
    Destination     Gateway         Genmask         Flags   Metric Ref    Use Iface
    
    184.82.152.96   0.0.0.0         255.255.255.248 U     0      0        0 eth0
    
    169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
    
    0.0.0.0         184.82.152.97   0.0.0.0         UG    0      0        0 eth0
    [root@localhost]# netstat -rn
    
    Kernel IP routing table
    
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    
    184.82.152.96   0.0.0.0         255.255.255.248 U         0 0          0 eth0
    
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
    
    0.0.0.0         184.82.152.97   0.0.0.0         UG        0 0          0 eth0
    • 查看DNS
    [root@localhost]#  cat /etc/resolv.conf
    • 配置hostname
    [root@localhost]# hostnamectl set-hostname mini1

你可能感兴趣的:(linux)