直接网线接法连接两台电脑

条件: 

   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 static
                 address 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, 结果类似

 


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值