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 ]
域名指向同一内网下服务器访问不到
配置域名对应的内网地址
[root@localhost app]# vim /etc/hosts
# 文件服务器
192.168.218.20 fastdfs.test.com
ubuntu18
查看操作系统版本
ubuntu 每个大版本的设置方式都不一样,一定要先确认服务器的系统版本。
cat /etc/issue
uname -a
修改 /etc/netplan/*.yaml 文件
[root@localhost ~]# sudo cd /etc/netplan
[root@localhost ~]# sudo vim 01-network-manager-all.yaml
network:
version: 2
ethernets:
ens3:
dhcp4: no
addresses:[192.168.2.210/24,]
gateway4: 192.168.2.1
[root@localhost ~]# sudo netplan apply
修改 DNS 临时生效
开机重启后该配置会被覆盖掉
[root@localhost ~]# sudo vim /etc/resolv.conf
nameserver 202.102.154.3
nameserver 114.114.114.114
nameserver 8.8.8.8
修改 DNS 永久生效
[root@localhost ~]# sudo vim /etc/systemd/resolved.conf
[Resolve]
DNS=202.102.154.3 114.114.114.114 8.8.8.8
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
配置生效
[root@localhost ~]# systemctl restart systemd-resolved.service