LoginSignup
4
3

More than 5 years have passed since last update.

Raspberrypi Zero over USB on Ubuntu16.04 (OTG)

Last updated at Posted at 2017-02-07

Ubuntu16.04にUSB接続したraspberrypiZeroをUSB経由でインターネットに接続する。(OTG接続)

用意するもの

  • config.txt
    dtoverlay=dwc2の1行を追記します。

  • cmdline.txt
    modules-load=dwc2,g_etherの1文をrootwaitのあとに追記します。改行せずスペース区切りで続けて記述するように注意します。

Ubuntu に RaspberryZero をUSB接続する。

デスクトップ > 設定 > ネットワーク > 有線 (ハードウェアアドレスからraspi zero を判断。) > オプション > IPv4設定
ローカルリンク専用へ変更
※ 再接続や母艦の再起動後にはまた設定が必要。
そのたびに有線接続**がインクリメントされてる。
誰か永続化方法教えてくださいw

Screenshot from 2017-02-05 11-52-20.png

Routing する

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o [internet iface名(eth0..wpl**)] -j MASQUERADE

※ 永続化するなら
vi /etc/sysctl.conf
- # sysctl -w net.ipv4.ip_forward=1
+ sysctl -w net.ipv4.ip_forward=1

iptables 永続化は省略...

リンク先のscriptを動かす。

https://gist.github.com/MarkJB/c1d72682142f545171aa207fb1634153
※以下はgithubのscriptを手動で行う手順
問題なくscriptが動く人、書き換えて使う人はリンク先のscriptを動かして作業完了。

接続情報を調べておく。

ifconfig

直接Webに繋がるIPのgatewayを控える [webIPのgatewayIP]
eth0 IP or wlp* IP
と、そのgatewayIP (192.168.1.1とか)

raspberrypiZero が接続されてるenps* の[LocalIP]
リンクローカルアドレス 169.254.xxx.xxx

raspberrypi Zero にログインする。

ssh pi@raspberrypi.local (pwはここでは省略)

raspberrypi側でRouting

sudo route add default gw [localIP] usb0
echo "nameserver [WebIPのgatewayIP]" | sudo resolvconf -a usb0

これで外部に繋がる(はず

参考:http://qiita.com/hasokon/items/bf88d2c9b7fb077b7797

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3