记录实现将window网络共享给树莓派linux
大约 1 分钟
配置windows
网络共享
将以太网(可访问internet)共享给以太网2(不可访问internet)
点击确认后会弹出窗口提示本机以太网2的ip被修改成192.168.137.1
, 后续需要手动修改成所需的ip.
修改以太网2的ip为实际所需的ip
配置树莓派linux
查看树莓派当前网口ip
pi@raspberrypi:~ $ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:03:30:04 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.2/24 brd 192.168.2.255 scope global eth0
valid_lft forever preferred_lft forever
inet 169.254.196.116/16 brd 169.254.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::f004:372:8df7:13c8/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether b8:27:eb:56:65:51 brd ff:ff:ff:ff:ff:ff
inet6 fe80::c4a0:903b:b3d1:9797/64 scope link tentative
valid_lft forever preferred_lft forever
添加给dev eth0
添加默认路由default via
地址为 192.168.2.1
pi@raspberrypi:~ $ sudo ip route add default via 192.168.2.1 dev eth0
测试公网连接
pi@raspberrypi:~ $ ping 223.5.5.5
PING 223.5.5.5 (223.5.5.5) 56(84) bytes of data.
64 bytes from 223.5.5.5: icmp_seq=1 ttl=119 time=13.9 ms
64 bytes from 223.5.5.5: icmp_seq=2 ttl=119 time=11.7 ms
64 bytes from 223.5.5.5: icmp_seq=3 ttl=119 time=20.1 ms
配置阿里云DNS(223.5.5.5)
pi@raspberrypi:~ $ sudo vi /etc/resolv.conf
pi@raspberrypi:~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 223.5.5.5
测试DNS
pi@raspberrypi:~ $ ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66: icmp_seq=1 ttl=49 time=65.8 ms
64 bytes from 110.242.68.66: icmp_seq=2 ttl=49 time=53.1 ms
^C
--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 53.133/59.474/65.816/6.346 ms