以太网连接rapberry pi(不通过路由)

62 views
Skip to first unread message

包乾

unread,
Aug 16, 2014, 10:50:44 AM8/16/14
to sh...@googlegroups.com
基本的问题很简单,如何只用一根网线连接linux的电脑和raspberry pi,而不是将两者都接在同一个路由器上通过路由分配ip并连接彼此。

要求是

1 尽量不使用外接显示器,且已知raspberry上已经启动了sshd。
2 在linux的电脑上尽量不使用gui或者专用软件,使用ip及iptable等基本工具进行连接

问题比较模糊还请指教!

Shell Xu

unread,
Aug 16, 2014, 11:04:32 AM8/16/14
to shlug
1. 你得有交叉线,不然免谈。
2. 装dnsmasq,把电脑弄成dhcp服务器。
3. respberry是dhcp吧?是的话插上去启动,读dhcp。dnsmasq会记录下他的IP。
4. ssh到这个ip。

这样可以么?


--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/blog/

Liang Guo

unread,
Aug 16, 2014, 11:20:15 AM8/16/14
to sh...@googlegroups.com

"宋为@凉拌茶叶"

unread,
Aug 16, 2014, 9:02:16 PM8/16/14
to sh...@googlegroups.com
现在电脑一般都是自适应网卡,不需要关心这个情况,如果不是自适应网卡,那简
直是中 奖了

于 2014年08月16日 23:03, Shell Xu 写道:
> 1. 你得有交叉线,不然免谈。
>


none_nobody

unread,
Aug 16, 2014, 10:56:42 PM8/16/14
to sh...@googlegroups.com
团结、紧张、严肃、活泼

包乾

unread,
Aug 16, 2014, 11:06:39 PM8/16/14
to sh...@googlegroups.com

嗯多谢,我回去试试

2014/08/17 0:04 "Shell Xu" <shell...@gmail.com>:

包乾

unread,
Aug 16, 2014, 11:07:54 PM8/16/14
to sh...@googlegroups.com

话说,以太网线接上电脑后,有没有类似dmesg或者lspci的工具可以侦测到有物理设备连接?

2014/08/17 0:04 "Shell Xu" <shell...@gmail.com>:
1. 你得有交叉线,不然免谈。

"宋为@凉拌茶叶"

unread,
Aug 16, 2014, 11:22:51 PM8/16/14
to sh...@googlegroups.com
用ifconfig可以看网卡状态啊
>> twitter: @shell909090 <https://twitter.com/shell909090>

包乾

unread,
Aug 16, 2014, 11:37:01 PM8/16/14
to sh...@googlegroups.com

可是网卡不插设备也可以从ifconfig里看到啊,只要内核模块正确的话,有何不同吗??

2014/08/17 12:22 宋为@凉拌茶叶 <leo_s...@126.com>:
用ifconfig可以看网卡状态啊

于 2014年08月17日 11:07, 包乾 写道:
话说,以太网线接上电脑后,有没有类似dmesg或者lspci的工具可以侦测到有物理设备连接?
2014/08/17 0:04 "Shell Xu" <shell...@gmail.com>:

1. 你得有交叉线,不然免谈。
2. 装dnsmasq,把电脑弄成dhcp服务器。
3. respberry是dhcp吧?是的话插上去启动,读dhcp。dnsmasq会记录下他的IP。
4. ssh到这个ip。

这样可以么?


在 2014年8月16日 下午10:50,包乾 <houke...@gmail.com>写道:

基本的问题很简单,如何只用一根网线连接linux的电脑和raspberry pi,而不是将两者都接在同一个路由器上通过路由分配ip并连接彼此。

要求是

1 尽量不使用外接显示器,且已知raspberry上已经启动了sshd。
2 在linux的电脑上尽量不使用gui或者专用软件,使用ip及iptable等基本工具进行连接

问题比较模糊还请指教!

--
-- You received this message because you are subscribed to the Google
Groups Shanghai Linux User Group group. To post to this group, send email
to sh...@googlegroups.com. To unsubscribe from this group, send email to
shlug+unsubscribe@googlegroups.com. For more options, visit this group

at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/blog/
twitter: @shell909090 <https://twitter.com/shell909090>
about.me: http://about.me/shell909090

--
-- You received this message because you are subscribed to the Google
Groups Shanghai Linux User Group group. To post to this group, send email
to sh...@googlegroups.com. To unsubscribe from this group, send email to
shlug+unsubscribe@googlegroups.com. For more options, visit this group at

https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
--- 您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout

Shell Xu

unread,
Aug 17, 2014, 12:43:53 AM8/17/14
to shlug
ethtool


--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN

---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/blog/

AR

unread,
Aug 17, 2014, 2:52:44 AM8/17/14
to sh...@googlegroups.com
DHCP这样的记录会灵活点。

如果OP你只要连上,并且RPi不会经常换网络(例如只放在一个LAN里不动)。可以考虑设置固定IP。

在启动的配置文件里可以添加设置启动后的IP,编辑启动分区 cmdline.txt 文件,启动参数里添加

ip=192.168.1.10 

之类的配置即可。

--
Silence is golden.

Bill Ryan

unread,
Aug 17, 2014, 9:27:27 PM8/17/14
to sh...@googlegroups.com
PC以及树莓派不是有LAN的LED指示灯么

从你的问题来看,目测是想通过一根网线连接树莓派以ssh进去配置啥的吧?树莓派显示只有hdmi接口,显示器是VGA接口的话确实不方便。

如果从正面解决你的问题,Shell的方案挺靠谱的。前提是你刷的镜像是dhcp方式获取ip的(一般的镜像都是这么干的)  

话说呀,现在路由器满大街都是,网线也不贵是吧,接到路由器的LAN口下使用不方便的多吗?配置好了之后甚至可以拿树莓派充当路由器(我在学校宿舍就这么干的)。


在 2014年8月17日 上午11:36,包乾 <houke...@gmail.com>写道:

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN

---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
from: billryan

Gmail-Mailbox

unread,
Aug 17, 2014, 10:08:51 PM8/17/14
to sh...@googlegroups.com
还有一个非常简单的方法,直接用usb-to-ttl的串口线缆接树莓派,可以不需要显示器,也不需网线,我都是用这个串口线来操作树莓派的,
如果有了无线网卡,就更方便了。
在无线网卡插入的情况下,启动了Pi,然后通过usb转ttl登陆上去,切换到管理员
# sudo su - 
接着查找设备:
#lsusb 如果有网卡就可以看到
再接着就是搜索附近的wi-fi的ssid
# iwlist  wlan0  scanning  | grep -i ssid
找到你的ssid然后 
# wpa_passphrase   你的SSID   你的密码   >>   /etc/wpa_supplicant/wpa_supplicant.conf 
再接下来就可以直接重新启动了。
# reboot 
如果想使用固定IP,直接写到配置文件里面就好。
# vim.tiny   /etc/network/interfaces
修改成如下内容就可以了,参考你实际情况写。
  1. auto lo  
  2.   
  3. iface lo inet loopback  
  4. iface eth0 inet static  
  5.   
  6. address 192.168.1.110  
  7. netmask 255.255.255.0  
  8. gateway 192.168.1.1  
  9.   
  10. allow-hotplug wlan0  
  11. iface wlan0 inet manual  
  12. wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf 

david pu

unread,
Aug 18, 2014, 1:13:18 AM8/18/14
to sh...@googlegroups.com
raspi和电脑之间建个NAT即可。
我这边板子上有USB OTG口,就是用USB cable通过RNDIS和PC建立NAT然后可以ssh过去,板子也可以通过PC share网络连到外面。
使用网线就应该更简单了:
设备端:
ifconfig eth0/rndis0 192.168.137.2 netmask 255.255.255.0 up
route add default gw 192.168.137.1 dev eth0

PC端:
sudo ifconfig eth1/usb0 192.168.137.1 netmask 255.255.255.0
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE

这样PC和设备应该就可以互相连接了
设备想上网,配下/etc/reslov.conf写和你PC上用的DNS server或者8.8.8.8
> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout



--
() ASCII Ribbon Campaign
/\ Keep it simple!

"宋为@凉拌茶叶"

unread,
Aug 18, 2014, 9:06:22 PM8/18/14
to sh...@googlegroups.com
大家的方法都太麻烦了啊,我来介绍个傻瓜化的。

我是这么搞的:

懒得调DNS什么的,如果你的Linux发行版用NetworkManager(一般来说是吧,比如
Ubuntu,比如openSUSE), 新建了有线连接,在IPv4里面的“方法”里面选“与其他
计算机共享”,把树梅派和电脑插上,选用你新建的这个有线连接。

NetworkManager自带DNS分配,会给树梅派一个IP(这个IP感觉是通过网卡号哈希
的一样,我重装树梅派系统无数次均未改过, 挺方便)。

然后开nmap扫描一下网段,除了10.42.0.1(你自己,NetworkManager用这个网段
分配IP)以外能Ping通的那个就 是树梅派了。

david pu

unread,
Aug 18, 2014, 9:20:35 PM8/18/14
to sh...@googlegroups.com
你这个就是我上面的GUI版哈哈~
> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> --- 您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
>
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问 https://groups.google.com/d/optout

none_nobody

unread,
Aug 19, 2014, 9:11:27 PM8/19/14
to sh...@googlegroups.com
赶脚是结果都对了,概念不对。
Reply all
Reply to author
Forward
0 new messages