Raspberry Piをbluetooth使用ルータとして活用する (Step5 iptables+ipforword)
iptables+ipforword
いままでの設定でRaspberry Piのインターネットとの通信はbluetoothを使うようになりました。いよいよ次は有線LAN側に接続されたRaspberry Pi以外の機器からの通信をRaspberry Piを経由してbluetooth側に流してあげます。
参考
俺でも解るIPTABLESも参考になりました。
iptablesの設定を保存(再起動しても初期化されない)するため、iptables-persistentパッケージを導入します。
pi@raspberrypi:~ $ sudo apt-get install iptables-persistent
iptablesを設定します。LAN側(192.168.11.0/24)からのパケットにはNAT(IPマスカレード)してあげます。最後の行で設定ファイルを追記して再起動してもルールが有効になるようにします。
pi@raspberrypi:~ $ sudo iptables -t nat -A POSTROUTING -s 192.168.11.0/24 -j MASQUERADE pi@raspberrypi:~ $ sudo iptables -I FORWARD -j ACCEPT pi@raspberrypi:~ $ sudo iptables-save | sudo tee -a /etc/iptables/rules.v4
ipフォワーディングを有効にします。/etc/sysctl.confを編集。
pi@raspberrypi:~ $ sudo nano /etc/sysctl.conf
net.ipv4.ip_forwardの設定がコメントアウトされているので
#net.ipv4.ip_forward = 1
#をとって、有効化します。
設定が終わったら、再起動して設定を有効にします。