条件:
1>同一个网段, 即 ip 最后一位不同,
2>掩码相同
3>同一个网关,网关也属于同一个网段(不一定要求是两个ip中的一个)
linux / 树莓派的配置如下:
电脑A配置如下: ***********************************
文件 /etc/rc.local 配置以下内容:
echo "config eth0"
ifconfig eth0 up
ifconfig eth0:1 192.168.1.2
文件 /etc/network/interfaces
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
电脑B配置如下: ***************************************
文件 /etc/rc.local 配置以下内容:
echo "config eth0"
ifconfig eth0 up
ifconfig eth0:1 192.168.1.1
文件 /etc/network/interfaces
iface eth0 inet staticaddress 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.1
*********************************************************
重启生效后, 用网线直接相连
电脑A上测试: ping 192.168.1.1
ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.331 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.290 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.263 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.339 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=0.341 ms
64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.256 ms
反过来, 电脑B 测试 ping 192.168.1.2, 结果类似