linux 基础操作(十)设置 ip

centos7

静态 ip

设置 ip
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3  ifdown-eth  
[root@localhost network-scripts]# vi ifcfg-enp0s3 

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
# 静态ip
BOOTPROTO="static"
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="enp0s3"
UUID="9dbd4c1e-86e9-4ff6-81f0-47951adcfffa"
DEVICE="enp0s3"
ONBOOT="yes"
# ip地址
IPADDR="192.168.211.243"
# 子网掩码
NETMASK="255.255.255.0"
# 网关
GATEWAY="192.168.211.254"
设置 DNS
[root@localhost network-scripts]# vi /etc/resolv.conf

# Generated by NetworkManager
nameserver 201.210.33.52
nameserver 201.130.33.60
# 国内
nameserver 114.114.114.114
# 阿里
nameserver 223.5.5.5
# 百度
nameserver 180.76.76.76
重启网卡
[root@localhost network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]

设置动态 ip

设置动态获取 ip
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3  ifdown-eth  
[root@localhost network-scripts]# vi ifcfg-enp0s3 

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
# 动态ip
BOOTPROTO="DHCP"
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="enp0s3"
UUID="9dbd4c1e-86e9-4ff6-81f0-47951adcfffa"
DEVICE="enp0s3"
ONBOOT="yes"
重启网卡
[root@localhost network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]

上一篇 linux 基础操作(九) 防火墙操作