centos及Ubuntu服务器修改DNS配置

公司办公网络网段通过DHCP自动分配IP,服务器网段是手动配置的固定IP,nameserver统一指向服务器网段的网关,最近由于公司路由器服务器网段DNS解析问题,不得不手动配置服务器的dns,以此记录下。

centos修改dns:

1:找到网络配置文件
bash 复制代码
cd /etc/sysconfig/network-scripts/

ll

-rw-r--r--. 1 root root   366 Apr 17  2023 ifcfg-eth0
-rw-r--r--. 1 root root   254 May 22  2020 ifcfg-lo
lrwxrwxrwx. 1 root root    24 Apr 17  2023 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root   654 May 22  2020 ifdown-bnep
-rwxr-xr-x. 1 root root  6532 May 22  2020 ifdown-eth
-rwxr-xr-x. 1 root root   781 May 22  2020 ifdown-ippp
-rwxr-xr-x. 1 root root  4540 May 22  2020 ifdown-ipv6
lrwxrwxrwx. 1 root root    11 Apr 17  2023 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root  2130 May 22  2020 ifdown-post
-rwxr-xr-x. 1 root root  1068 May 22  2020 ifdown-ppp
-rwxr-xr-x. 1 root root   870 May 22  2020 ifdown-routes
-rwxr-xr-x. 1 root root  1456 May 22  2020 ifdown-sit
-rwxr-xr-x. 1 root root  1621 Dec  9  2018 ifdown-Team
-rwxr-xr-x. 1 root root  1556 Dec  9  2018 ifdown-TeamPort
-rwxr-xr-x. 1 root root  1462 May 22  2020 ifdown-tunnel
lrwxrwxrwx. 1 root root    22 Apr 17  2023 ifup -> ../../../usr/sbin/ifup
-rwxr-xr-x. 1 root root 12415 May 22  2020 ifup-aliases
-rwxr-xr-x. 1 root root   910 May 22  2020 ifup-bnep
-rwxr-xr-x. 1 root root 13758 May 22  2020 ifup-eth
-rwxr-xr-x. 1 root root 12075 May 22  2020 ifup-ippp
-rwxr-xr-x. 1 root root 11893 May 22  2020 ifup-ipv6
lrwxrwxrwx. 1 root root     9 Apr 17  2023 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root   650 May 22  2020 ifup-plip
-rwxr-xr-x. 1 root root  1064 May 22  2020 ifup-plusb
-rwxr-xr-x. 1 root root  4997 May 22  2020 ifup-post
-rwxr-xr-x. 1 root root  4154 May 22  2020 ifup-ppp
-rwxr-xr-x. 1 root root  2001 May 22  2020 ifup-routes
-rwxr-xr-x. 1 root root  3303 May 22  2020 ifup-sit
-rwxr-xr-x. 1 root root  1755 Dec  9  2018 ifup-Team
-rwxr-xr-x. 1 root root  1876 Dec  9  2018 ifup-TeamPort
-rwxr-xr-x. 1 root root  2780 May 22  2020 ifup-tunnel
-rwxr-xr-x. 1 root root  1836 May 22  2020 ifup-wireless
-rwxr-xr-x. 1 root root  5419 May 22  2020 init.ipv6-global
-rw-r--r--. 1 root root 20678 May 22  2020 network-functions
-rw-r--r--. 1 root root 30988 May 22  2020 network-functions-ipv6
2:找到带网卡名的配置文件并修改配置文件
bash 复制代码
vi ifcfg-eth0


DEVICE=eth0
ONBOOT=yes
IPADDR=********
NETMASK=******
GATEWAY=******

#手动改成自己需要的dns
DNS1=114.114.114.114
3:重启网络
bash 复制代码
systemctl restart network

Ubuntu服务器修改dns:

1:Ubuntu是通过netplan管理的,还是找到网络配置文件
bash 复制代码
cd  /etc/netplan
ll

-rw-r--r--  1 root root  585 Nov 18 03:14 50-cloud-init.yaml

vim 50-cloud-init.yaml
2:修改配置文件,如果多网卡机器找对自己的网卡名,然后修改对应的nameserver下的addresses为自己想要的dns即可
bash 复制代码
network:
    ethernets:
        enp5s0:
            addresses:
            - 192.168.199.177/24
            gateway4: 192.168.199.1
            nameservers:
                addresses: [114.114.114.114]
                search:
                - 192.168.199.1
    version: 2
3:应用配置到网络
bash 复制代码
netplan apply
相关推荐
Deng8723473485 小时前
代码语法检查工具
linux·服务器·windows
云计算老刘6 小时前
3.Shell 变量基础知识
chrome·正则表达式·centos·云计算
霍夫曼7 小时前
UTC时间与本地时间转换问题
java·linux·服务器·前端·javascript
siriuuus7 小时前
Redis 安装、多实例部署、主从复制及 Cluster 实践
数据库·redis·centos
月熊8 小时前
在root无法通过登录界面进去时,通过原本的普通用户qiujian如何把它修改为自己指定的用户名
linux·运维·服务器
漫漫求8 小时前
ubuntu22.04 安装报错:grub-install/dev/sda 解决方案
ubuntu
打码人的日常分享9 小时前
智慧城市一网统管建设方案,新型城市整体建设方案(PPT)
大数据·运维·服务器·人工智能·信息可视化·智慧城市
风掣长空10 小时前
Google Test (gtest) 新手完全指南:从入门到精通
运维·服务器·网络
LEEE@FPGA11 小时前
ZYNQ MPSOC linux hello world
linux·运维·服务器
郝学胜-神的一滴11 小时前
Linux定时器编程:深入理解setitimer函数
linux·服务器·开发语言·c++·程序人生