更改前检查路线
user@ubuntu--k8s-master:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 enp0s3
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s3
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
user@ubuntu--k8s-master:~$
我们去改一下ip
user@ubuntu--k8s-master:~$ sudo ifconfig enp0s3 192.168.0.30 netmask 255.255.255.0 up
user@ubuntu--k8s-master:~$
可路由信息现在为空
user@ubuntu--k8s-master:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
user@ubuntu--k8s-master:~$
现在,我正在尝试添加规则......
user@ubuntu--k8s-master:~$ sudo route add default gw 192.168.0.1 enp0s3
SIOCADDRT: Network is unreachable
user@ubuntu--k8s-master:~$
user@ubuntu--k8s-master:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
user@ubuntu--k8s-master:~$
怎么办?我必须添加之前的规则吗?
user@ubuntu--k8s-master:~$ netstat | grep enp0s3
user@ubuntu--k8s-master:~$
user@ubuntu--k8s-master:~$ nmcli con
NAME UUID TYPE DEVICE
Profile 1 64280569-78e6-496d-acc8-69215fd4c57e ethernet enp0s3
user@ubuntu--k8s-master:~$
user@ubuntu--k8s-master:~$ sudo dhclient
cmp: EOF on /tmp/tmp.xkMIfDSrZx which is empty
user@ubuntu--k8s-master:~$
user@ubuntu--k8s-master:~$ cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0
user@ubuntu--k8s-master:~$
其他
user@ubuntu--k8s-master:~$ resolvectl status
Global
LLMNR setting: no
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 190.157.8.100
DNS Servers: 190.157.8.100
190.157.8.46
100.70.133.50
100.70.133.51
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
22.172.in-addr.arpa
23.172.in-addr.arpa
24.172.in-addr.arpa
25.172.in-addr.arpa
26.172.in-addr.arpa
27.172.in-addr.arpa
28.172.in-addr.arpa
29.172.in-addr.arpa
30.172.in-addr.arpa
31.172.in-addr.arpa
corp
d.f.ip6.arpa
home
internal
intranet
lan
local
private
test
Link 2 (enp0s3)
Current Scopes: DNS
DefaultRoute setting: yes
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 190.157.8.100
DNS Servers: 190.157.8.100
190.157.8.46
100.70.133.50
100.70.133.51
DNS Domain: ~.
lines 6-53/53 (END)
系统控制
user@ubuntu--k8s-master:~$ systemctl | grep dhcp
user@ubuntu--k8s-master:~$
如何检查 dhcp 是否正在运行?更重要的是如何停止它?
答案1
Anita,看起来接口配置为使用 DHCP,并且此服务正在干扰您的手动命令,您的命令看起来是正确的。您的netstat
命令的输出可能混合了您的手动命令和 DHCP 服务的结果。169.254.0.0
输出中的ipnetstat
表示网络接口正在由 DHCP 服务处理,您必须停止它才能手动配置接口。您可能需要禁用其他服务,例如网络管理器。您还可以使用ip route add
和ip addr add
命令作为route
和的替代netstat