一、网卡方式配置
1 临时配置
配置静态IP并指向自己(yam格式 不能使用tab键 只能使用空格)
[root@ubuntu22 ~]#cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
#dhcp4: true
addresses: [10.0.0.153/24]
gateway4: 10.0.0.2
nameservers:
addresses: [10.0.0.2,223.5.5.5]
version: 2
[root@ubuntu22 ~]#netplan apply
[root@ubuntu22 ~]#nslookup www.baidu.com
Server: 10.0.0.2
Address: 10.0.0.2#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 220.181.38.149
Name: www.a.shifen.com
Address: 220.181.38.150
[06:32:05 root@ubuntu22 ~]#cat /etc/resolv.conf
nameserver 223.5.5.5
#nameserver 127.0.0.53
#options edns0 trust-ad
search .
使用 systemctl restart systemd-resolved.service 会让配置失效
2 永久配置
systemd-resolved 服务为本地应用程序提供了网络名字解析服务, 系统通过它对外进行 dns 请求。
[root@ubuntu ~]# ll /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Apr 21 2022 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
先删除文件
[root@ubuntu ~]# rm -f /etc/resolv.conf
再将文件链接到 /run/systemd/resolve/resolv.conf
[root@ubuntu ~]# ln -sv /run/systemd/resolve/resolv.conf /etc/resolv.conf
'/etc/resolv.conf'-> '/run/systemd/resolve/resolv.conf'
重启服务
[root@ubuntu22 ~]#netplan apply
[root@ubuntu22 ~]#systemctl restart systemd-resolved.service
二、非网卡方式设置
步骤继承永久配置
设置全局DNS(找到文件下注释的DNS进行添加)
[root@ubuntu ~]# vim /etc/systemd/resolved.conf
DNS=223.5.5.5 223.6.6.6
三、selinux 问题解决
selinux 有一个机制,就是软件包相关的文件目录都规定好了,如果修改了路径,或者是外来的文件,就有可能导致服务起不来
执行setenforce 0,可以不用重启。