IP addr show 命令显示两个 ip 地址

IP addr show 命令显示两个 ip 地址

我已经在 ubuntu 服务器上设置了静态 IP,我可以使用静态 IP 通过 SSH 进入服务器 ( 192.168.178.27)。但是当我使用ifconfig命令 时,我看到了不同的 IP ( 192.168.178.24)。此外,当我运行 时ip addr show,我看到同一接口有两个 IP ( wlp58s0)。

我该如何纠正这个问题?

$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 94:c6:91:14:86:91 brd ff:ff:ff:ff:ff:ff
3: wlp58s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 88:b1:11:99:66:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.24/24 brd 192.168.178.255 scope global dynamic wlp58s0
       valid_lft 85719sec preferred_lft 85719sec
    inet 192.168.178.27/24 brd 192.168.178.255 scope global secondary wlp58s0


$ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:91:0b:d3:fb  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 123  bytes 9912 (9.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 123  bytes 9912 (9.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp58s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.24  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fe80::bb3e:5309:292d:e32b  prefixlen 64  scopeid 0x20<link>
        ether 88:b1:11:99:66:00  txqueuelen 1000  (Ethernet)
        RX packets 14904  bytes 21544564 (21.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2030  bytes 244273 (244.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

内容/etc/network/interfaces

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# Generated by debian-installer.

# The loopback interface
auto lo
iface lo inet loopback

auto wlp58s0
iface wlp58s0 inet static
address 192.168.178.27
netmask 255.255.255.0
gateway 192.168.178.1
dns-nameservers  8.8.8.8 8.8.4.4

内容netconf

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    wlp58s0:
      dhcp4: yes
      addresses: [192.168.178.27/24]
      gateway4: 192.168.178.1
      nameservers:
         addresses: [8.8.8.8,8.8.4.4]

答案1

您的配置无法按预期工作,因为无线接口需要定向到特定的 SSID 并提供 WPA2 密码。您的 /etc/network/interfaces 和 netplan 配置都没有这样做。此外,您的 netplan 说 dhcp4:yes,而实际上您指定了一个静态 IP。您还指定乙太網当wlp58s0是无线的时候;应该是无线网络

坦率地说,如果网络管理器正在运行,我会从 /etc/network/interfaces 中完全删除设置,并将 netplan 恢复为其通常的配置。也就是说,重命名为当前必须的文件:/etc/netplan/01-network-manager-all.yaml。然后将其恢复为默认措辞:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

如果你想尝试 netplan,并且你正在运行 Ubuntu 17.10 或更高版本然后我将从 /etc/network/interfaces 中删除所有 wlp58s0 设置,并将 netplan 编辑为:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  wifis:
    wlp58s0:
      dhcp4: no
      addresses: [192.168.178.27/24]
      gateway4: 192.168.178.1
      nameservers:
         addresses: [8.8.8.8,8.8.4.4]
      access-points: 
              "your_router":
          password: "your_wpa2_password"

请注意并遵循空格和缩进。另请注意,SSID 和密码在引号“中”。接下来,运行:

sudo netplan apply

重启。有什么改善吗?

相关内容