设置静态 IP 时接口停止检索页面

设置静态 IP 时接口停止检索页面

下面是我当前的设置,主要的以太网连接配置了静态 IP,并且工作正常。另外两个接口使用 DHCP 连接到不同的 Android 热点。我还配置了路由,以便每个接口都可以独立接收/发送流量

下面是我的完整工作/etc/network/interfaces文件

root@poweredge:/etc/network# cat interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug enp1s0
#iface enp1s0 inet dhcp
iface enp1s0 inet static
        address 192.168.1.212
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1

auto wlx74da388c32d0
iface wlx74da388c32d0 inet dhcp
        wpa-ssid four
        wpa-psk fcac8bd4439859aadf1457463f47f49091acb02895bd5a28914a1fc36969c66d
        post-up ip route add default via 172.16.11.254 table wlx74da388c32d0
        post-up ip rule add from 172.16.11.107 lookup wlx74da388c32d0



auto wlx74da388c32c7
iface wlx74da388c32c7 inet dhcp
        wpa-ssid one
        wpa-psk e629e0873738c638cde76ae81487effb28b0e22c309c9e163996e389a313c14c
        post-up ip route add default via 192.168.43.1 table wlx74da388c32c7
        post-up ip rule add from 192.168.43.209 lookup wlx74da388c32c7

我已使用以下命令确认每个接口都独立工作

curl --interface wlx74da388c32c7 ifconfig.co
curl --interface wlx74da388c32d0 ifconfig.co
curl --interface enp1s0 ifconfig.co

每个curl 命令都按预期显示连接的公共IP 地址。这正是我希望事情顺利进行的方式。

但是,当我在其中一个无线接口上设置静态 IP 时,我遇到了问题。例如,当我将接口更改wlx74da388c32c7为静态 IP 时,如下所示

auto wlx74da388c32c7
iface wlx74da388c32c7 inet static
        address 192.168.43.100
        netmast 255.255.255.0
        gateway 192.168.43.1
        wpa-ssid one
        wpa-psk e629e0873738c638cde76ae81487effb28b0e22c309c9e163996e389a313c14c
        post-up ip route add default via 192.168.43.1 table wlx74da388c32c7
        post-up ip rule add from 192.168.43.100 lookup wlx74da388c32c7

当我尝试使用任何界面获取页面时,curl 就会挂起。

下面是我的 rt_tables

root@poweredge:/etc/iproute2# cat rt_tables
#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
10 wlx74da388c32d0
11 wlx74da388c32c7

下面是我ip a在 wlx74da388c32c7 接口上设置静态 IP 后的命令

root@poweredge:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:1e:4f:cd:c1:5f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.212/24 brd 192.168.1.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::21e:4fff:fecd:c15f/64 scope link 
       valid_lft forever preferred_lft forever
3: wlx74da388c32c7: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 74:da:38:8c:32:c7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.100/24 brd 192.168.43.255 scope global wlx74da388c32c7
       valid_lft forever preferred_lft forever
4: wlx74da388c32d0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 74:da:38:8c:32:d0 brd ff:ff:ff:ff:ff:ff
    inet 172.16.11.107/24 brd 172.16.11.255 scope global wlx74da388c32d0
       valid_lft forever preferred_lft forever

我的ip route list何时使用 DHCP

root@poweredge:~# ip route list
default via 192.168.1.1 dev enp1s0 onlink 
172.16.11.0/24 dev wlx74da388c32d0 proto kernel scope link src 172.16.11.107 
192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.212 
192.168.43.0/24 dev wlx74da388c32c7 proto kernel scope link src 192.168.43.209 

我的ip rule list何时使用 DHCP

root@poweredge:~# ip rule list
0:  from all lookup local 
32764:  from 192.168.43.209 lookup wlx74da388c32c7 
32765:  from 172.16.11.107 lookup wlx74da388c32d0 
32766:  from all lookup main 
32767:  from all lookup default 

有人知道我做错了什么吗?

答案1

在你的输出中IP规则列表你有ip192.168.43.209该 IP 不匹配192.168.43.100

为了简化您的路由表,您可以更改为:

post-up ip rule add from 192.168.43.0/24 lookup wlx74da388c32c7

相关内容