我首先要说网络不是我的强项,我正在尝试配置一些子接口,以便我正在使用的一些代码将有更多的套接字来本地绑定.到目前为止我已经完成了以下操作,我可以在本地绑定到我的子接口192.168.2.210,但我无法与它建立远程连接.
这是我的ifconfig:
eth0 Link encap:Ethernet HWaddr 00:50:56:BB:00:0B inet addr:10.6.19.18 Bcast:10.255.255.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:febb:b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1056026 errors:0 dropped:0 overruns:0 frame:0 TX packets:638290 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:237037186 (226.0 MiB) TX bytes:126161362 (120.3 MiB) eth0:1 Link encap:Ethernet HWaddr 00:50:56:BB:00:0B inet addr:192.168.2.210 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
以下是我尝试配置eth0:1的内容
ifconfig eth0:1 192.168.2.210/32 up ip route add 192.168.2.210/32 via 10.6.19.18
这是我的netstat -r输出:
192.168.2.210 devserv. 255.255.255.255 UGH 0 0 0 eth0 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 10.6.19.0 * 255.255.255.0 U 0 0 0 eth0 link-local * 255.255.0.0 U 0 0 0 eth0 default 10.6.19.1 0.0.0.0 UG 0 0 0 eth0
有什么想法吗?谢谢你的期待
解决方法
ditch ifconfig正在逐步淘汰iproute2包;
root@bensley-n2:~# ip address show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff 3: wlan0: <BROADCAST,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0 inet6 fe80::76ea:3aff:fead:2e00/64 scope link valid_lft forever preferred_lft forever 4: virbr0: <NO-CARRIER,UP> mtu 1500 qdisc noqueue state DOWN link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 root@bensley-n2:~# ip address add 1.1.1.1/24 dev wlan0 root@bensley-n2:~# ip address show 1: lo: <LOOPBACK,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0 inet 1.1.1.1/24 scope global wlan0 inet6 fe80::76ea:3aff:fead:2e00/64 scope link valid_lft forever preferred_lft forever 4: virbr0: <NO-CARRIER,UP> mtu 1500 qdisc noqueue state DOWN link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 root@bensley-n2:~# ip route show default via 192.168.0.1 dev wlan0 1.1.1.0/24 dev wlan0 proto kernel scope link src 1.1.1.1 192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.5 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
(你可以缩写ip命令:ip address add可以一直缩短到ip aa,而ip address show可以缩短为ip a s.如果你没有指定第二个参数,show是默认动作,所以你可以输入ip a,如果你想真的很简洁.)
您无需为本地子网添加路由.