條件:
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, 結果類似