我需要从 DHCP 服务器租用多个 IP 地址,并在单台计算机上同时使用它们。
其连接方式如下:具有 5 个本地 IP 地址的计算机:192.168.1.2-6 通过 Lan 端口连接到 openwrt 路由器,该路由器租用了 5 个 IP 地址,具有 5 个虚拟 WAN 端口,每个端口具有不同的 MAC 地址。
我设法让第二部分与 kmod-macvlan 包一起工作。我的设置如下:/etc/rc.local:
ip link add link eth0.2 eth1 type macvlan
ifconfig eth1 hw ether 54:E6:FC:B7:00:00
ip link add link eth0.2 eth2 type macvlan
ifconfig eth2 hw ether 54:E6:FC:B7:00:01
ip link add link eth0.2 eth3 type macvlan
ifconfig eth3 hw ether 54:E6:FC:B7:00:02
ip link add link eth0.2 eth4 type macvlan
ifconfig eth4 hw ether 54:E6:FC:B7:00:03
ip link add link eth0.2 eth5 type macvlan
ifconfig eth5 hw ether 54:E6:FC:B7:00:04
ifup -a
在/etc/config/网络:
config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' '127.0.0.1'
option 'netmask' '255.0.0.0'
config 'interface' 'lan'
option 'ifname' 'eth0.1'
option 'type' 'bridge'
option 'proto' 'static'
option 'ipaddr' '192.168.1.1'
option 'netmask' '255.255.255.0'
config 'interface' 'wan'
option 'ifname' 'eth0.2'
option 'proto' 'dhcp'
config 'switch'
option 'name' 'rtl8366rb'
option 'reset' '1'
option 'enable_vlan' '1'
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '1'
option 'ports' '1 2 3 4 5t'
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '2'
option 'ports' '0 5t'
config 'interface' 'wan1'
option 'ifname' 'eth1'
option 'proto' 'dhcp'
option 'defaultroute' '0'
option 'peerdns' '0'
option 'gateway' '0.0.0.0'
config 'interface' 'wan2'
option 'ifname' 'eth2'
option 'proto' 'dhcp'
option 'defaultroute' '0'
option 'peerdns' '0'
option 'gateway' '0.0.0.0'
config 'interface' 'wan3'
option 'ifname' 'eth3'
option 'proto' 'dhcp'
option 'defaultroute' '0'
option 'peerdns' '0'
option 'gateway' '0.0.0.0'
config 'interface' 'wan4'
option 'ifname' 'eth4'
option 'proto' 'dhcp'
option 'defaultroute' '0'
option 'peerdns' '0'
option 'gateway' '0.0.0.0'
config 'interface' 'wan5'
option 'ifname' 'eth5'
option 'proto' 'dhcp'
option 'defaultroute' '0'
option 'peerdns' '0'
option 'gateway' '0.0.0.0'
ifconfig:
br-lan Link encap:Ethernet HWaddr 54:E6:FC:B7:**:**
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:168 errors:0 dropped:0 overruns:0 frame:0
TX packets:164 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17038 (16.6 KiB) TX bytes:33230 (32.4 KiB)
eth0 Link encap:Ethernet HWaddr 54:E6:FC:B7:**:**
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:719 errors:0 dropped:0 overruns:94459 frame:0
TX packets:286 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:128743 (125.7 KiB) TX bytes:57352 (56.0 KiB)
Interrupt:4
eth0.1 Link encap:Ethernet HWaddr 54:E6:FC:B7:**:**
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:219 errors:0 dropped:0 overruns:0 frame:0
TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:24692 (24.1 KiB) TX bytes:40289 (39.3 KiB)
eth0.2 Link encap:Ethernet HWaddr 54:E6:FC:B7:**:**
inet addr:192.168.99.8 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:180 errors:0 dropped:0 overruns:0 frame:0
TX packets:70 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:31280 (30.5 KiB) TX bytes:15492 (15.1 KiB)
eth1 Link encap:Ethernet HWaddr 54:E6:FC:B7:00:00
inet addr:192.168.99.101 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:89 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17942 (17.5 KiB) TX bytes:2476 (2.4 KiB)
eth2 Link encap:Ethernet HWaddr 54:E6:FC:B7:00:01
inet addr:192.168.99.102 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:83 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16826 (16.4 KiB) TX bytes:2065 (2.0 KiB)
eth3 Link encap:Ethernet HWaddr 54:E6:FC:B7:00:02
inet addr:192.168.99.103 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:76 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:15640 (15.2 KiB) TX bytes:1259 (1.2 KiB)
eth4 Link encap:Ethernet HWaddr 54:E6:FC:B7:00:03
inet addr:192.168.99.104 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:69 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:15220 (14.8 KiB) TX bytes:1259 (1.2 KiB)
eth5 Link encap:Ethernet HWaddr 54:E6:FC:B7:00:04
inet addr:192.168.99.105 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:81 errors:0 dropped:0 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16868 (16.4 KiB) TX bytes:2293 (2.2 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:51 errors:0 dropped:0 overruns:0 frame:0
TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4065 (3.9 KiB) TX bytes:4065 (3.9 KiB)
现在我如何告诉路由器将以下静态 LAN IP 地址与虚拟 WAN 端口配对:
192.168.1.2-eth1
192.168.1.3-eth2
192.168.1.4-eth3
192.168.1.5-eth4
192.168.1.6-eth6
进入后 192.168.1.2 网络无法访问
ip route add 192.168.1.2 dev eth1