我遇到了网络设置如下的情况:
在此图中,我的计算机 A 连接到 WiFi DSL 路由器,该路由器连接到互联网。计算机 A 和 B 直接连接到网络接口,无需任何路由器或交换机。我正在尝试设置我的计算机 B,以便它可以通过计算机 A 访问互联网。我对网络有非常基本的了解,我的假设(经过一些研究)是通过添加正确的静态路由来实现的,但我不知道应该在哪台计算机上添加哪个 IP。有什么帮助吗?
注意:我的两个系统都运行 Ubuntu。
计算机A的ifconfig:
eth0 Link encap:Ethernet HWaddr 00:23:5a:a2:22:04
inet addr:192.168.1.17 Bcast:192.168.1.31 Mask:255.255.255.240
inet6 addr: fe80::223:5aff:fea2:2204/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:323621697 errors:0 dropped:0 overruns:0 frame:0
TX packets:90168726 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:487306002830 (487.3 GB) TX bytes:5958302707 (5.9 GB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4998 errors:0 dropped:0 overruns:0 frame:0
TX packets:4998 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:465330 (465.3 KB) TX bytes:465330 (465.3 KB)
wlan0 Link encap:Ethernet HWaddr 00:21:00:dd:78:67
inet addr:192.168.1.6 Bcast:192.168.1.15 Mask:255.255.255.240
inet6 addr: fe80::221:ff:fedd:7867/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:88838 errors:0 dropped:0 overruns:0 frame:10052432
TX packets:74404 errors:56 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:45915165 (45.9 MB) TX bytes:12858677 (12.8 MB)
Interrupt:18
计算机B的ifconfig:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether ac:87:a3:16:3c:ce
inet6 fe80::ae87:a3ff:fe16:3cce%en0 prefixlen 64 scopeid 0x4
inet 192.168.1.18 netmask 0xfffffff0 broadcast 192.168.1.31
nd6 options=1<PERFORMNUD>
media: autoselect (1000baseT <full-duplex,flow-control>)
status: active
en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
ether 6c:40:08:a7:f1:7e
nd6 options=1<PERFORMNUD>
media: autoselect (<unknown type>)
status: inactive
en2: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 2a:00:00:5e:ee:00
media: autoselect <full-duplex>
status: inactive
en3: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 2a:00:00:5e:ee:01
media: autoselect <full-duplex>
status: inactive
p2p0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 2304
ether 0e:40:08:a7:f1:7e
media: autoselect
status: inactive
awdl0: flags=8902<BROADCAST,PROMISC,SIMPLEX,MULTICAST> mtu 1484
ether 6a:8a:6e:bb:a5:d4
nd6 options=1<PERFORMNUD>
media: autoselect
status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether ae:87:a3:61:0d:00
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
member: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 7 priority 0 path cost 0
nd6 options=1<PERFORMNUD>
media: <unknown type>
status: inactive
答案1
您的 A 计算机需要在此设置中充当路由器。取消注释此行
#net.ipv4.ip_forward=1
在 A 上的 /etc/sysctl.conf 中。它将在下次系统启动时打开转发。然后执行
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
立即开启转发。
完成后,您需要在 DSL 路由器中设置静态路由。有了您的子网,它将如图所示
此设置告诉您的路由器通过 192.168.1.7 网关路由发往 192.168.1.16 子网的数据包。因为 1.7 接口位于路由器子网上。
更新
如果没有 DHCP,所有地址都是固定的 /etc/network/interfaces 示例在 A 计算机上:
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address 192.168.1.7
netmask 255.255.255.240
broadcast 192.168.1.15
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
auto eth0
iface eth0 inet static
address 192.168.1.17
netmask 255.255.255.240
broadcast 192.168.1.31
B 计算机上的 /etc/network/interfaces 示例:
auto lo
iface lo inet loopback
auto en0
iface en0 inet static
address 192.168.1.18
netmask 255.255.255.240
broadcast 192.168.1.31
gateway 192.168.1.17
dns-nameservers 8.8.8.8 8.8.4.4
之后你需要执行
sudo /etc/init.d/networking restart