我尝试设置静态 IP 地址(192.168.2.1)
这里的输出ifconfig
enp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether c8:1f:66:06:94:a1 txqueuelen 1000 (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 36920 bytes 133557122 (133.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36920 bytes 133557122 (133.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlx4c0fc7f11daf: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.8 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::8955:c94:4868:c112 prefixlen 64 scopeid 0x20<link>
ether 4c:0f:c7:f1:1d:af txqueuelen 1000 (Ethernet)
RX packets 21101 bytes 26754759 (26.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11273 bytes 1150027 (1.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我使用 wifi 适配器连接:
wlx4c0fc7f11daf: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.8 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::8955:c94:4868:c112 prefixlen 64 scopeid 0x20<link>
ether 4c:0f:c7:f1:1d:af txqueuelen 1000 (Ethernet)
RX packets 21101 bytes 26754759 (26.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11273 bytes 1150027 (1.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我的问题是:我应该在“etc/network/interfaces”中添加什么?
实际内容是:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
答案1
附加以下内容为/etc/network/interfaces
enp3s0 设备分配静态地址:
auto enp3s0
iface enp3s0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway <your-router-ip-address-goes-here>
dns-nameservers 1.1.1.1 8.8.8.8