FreeBSD でおうちのルーター (CBUG meeting 2014/05/17)

H
FreeBSD でおうちのルーター
vnet jail + mpd5 + ipfw とか
cache DNS sever + 内部に閉じた private DNS
2014年5月17日
於 CBUG Meeting
小野 寛生
はじめに
● ブロードバンド無線LANルーターとかあるのになん
で FreeBSD でちまちま設定すんの?
趣味です
設定
● vnet jail はとがわさんのページを参考にしました
– http://toga.vegalta.org/wordpress/2013/10/08/481
● mpd5 の設定はまきHikiを参考にしました
– http://triaez.kaisei.org/~mzaki/hiki/?FreeBSD/ネットワーク
● ipfw (w/NAT) は man を読んでがんばりました
– あとは、FreeBSD 6.x の頃に hrs さんに教えてもらった
こととか
– man を読むと、nat 以外にも not antispoof とか table
とか {} で括れるとか
vnet jail
● jail + ネットワークスタック分離
– (Solaris zone を目指した?)
● kernel config に
options VIMAGE
が必要
– まだ安定していないので GENERIC に入っていない
– 最近 pf が host で使えるようになった
VIMAGE (vnet) による分離の例
● 通常の jail
– 同じ interface が見える
● ifconfig -a
● jexec jname ifconfig -a
● vnet jail
– interface は vnet (host と jail ごと) に所属する
– 例
● ifconfig epair0 create → host に epair0a, epair0b
● ifconfig epair0b vnet jname
– ifconfig -a → epari0a だけ出てくる
– jexec jname ifconfig -a → epair0b だけ出てくる
構成 (物理)
EeeBox
Intel(R) Atom(TM) CPU N270
RAM 2GB
SSD 120GB くらい
構成 (ネットワーク?)
mpd
+
ipfw
ISP
Flets Sq.
bridge0
re0
ng0
ng1
SW hub
epair3a
epair0a
ue0
epair0b
ral0
客用AP
epair2b
epair3b
epair1b epair1a
outer
inner
gate
家用の無線
APもこっち
re0
bridge1
forwarding 有効
何をしているか
● gate
– mpd5 で ISP と Flets sq. に PPPoE 接続
– ipfw + nat でゲートウェイ&ファイアウォール
– unbound で cache DNS server
– sshd (の予定)
● inner
– yadifad で 勝手 authoritative DNS server
● 勝手 = private IP に振っている
– isc-dhcpd bridge はこれのための面も
● outer
– 外向け httpd (の予定)
ファイアウォール
● ipfw + nat
– nat 10 ip from any to any via ng0
の形でないと NAT が通らなかった。
– NAT ルールの前に
deny ip from any to 192.168.0.0/16 via {ue0,ng0,ng1}
deny ip from 192.168.0.0/16 to any via {ue0,ng0,ng1}
で (たぶん) 外から入り込まれるのを防げていると思う。
VIMAGE (vnet) による分離
● jexec gate netstat -a
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
unbound unbound 3449 3 udp4 192.168.8.1:53 *:*
unbound unbound 3449 4 tcp4 192.168.8.1:53 *:*
unbound unbound 3449 5 udp4 192.168.16.1:53 *:*
unbound unbound 3449 6 tcp4 192.168.16.1:53 *:*
unbound unbound 3449 9 udp6 *:53 *:*
unbound unbound 3449 10 tcp6 *:53 *:*
root sendmail 1511 4 tcp4 127.0.0.1:25 *:*
root mpd5 1454 16 tcp6 ::1:5005 *:*
root mpd5 1454 19 tcp4 *:5006 *:*
root syslogd 1445 6 udp6 *:514 *:*
root syslogd 1445 7 udp4 *:514 *:*
● tcp,udp はこれだけ。赤は設定漏れで外向けにも開いているもの
● あとは、外向けに sshd, http (redirect) を開ける予定
ezjail + vnet の設定
● ezjail じゃなくてもいいんですが
– jail.conf 直とか qjail, qjail2 … とかあるみたいです。
● /etc/rc.conf
ezjail_enable=”YES”
jail_parameters=”vnet=new”
● /usr/local/etc/ezjail/jailname ファイル
– export_jname_ip=”0.0.0.0” (別途 ifconfig で)
– export_jname_parameters=”allow_raw_sockets=1”
– export_jname_parameters= 
”allow_raw_sockets=1 vnet=new”
mpd5 で必要
全体なら rc.conf
一部なら ezjail/* 別に
ezjail + vnet の設定 (続き)
● /usr/local/etc/ezjail/jailname ファイル
– export ezjail_jname_{pre,post}startN=... で
● ifconfig create epair0 up とか
● ifconfig ue0 vnet jname とか
● jexec jname ifconfig epair0b 192.168.0.2/24 とか
– /etc/rc の実行
● export ezjail_jname_exec_start=””
…
● export ezjail_jname_poststartN=”/bin/sh /etc/rc”
– poststart の最後に書く
– interface が設定された後に daemon が起動されるようにするため
mpd.conf
● アドレスを取得したところで、ipfw と unbound を
restart する
– mpd.conf
● set iface up-script script-path
で次の形式でスクリプトが起動される
– up-script if proto local-ip remote-ip authname
[dns1 dns1-ip] [dns2 dns2-ip] peer-address
– これに対応したスクリプトで
設定ファイルにアドレスを書き込んで restart
mpd.conf
● アドレスを取得したところで、ipfw と unbound を
restart する
– mpd.conf
● set iface up-script script-path
で次の形式でスクリプトが起動される
– up-script if proto local-ip remote-ip authname
[dns1 dns1-ip] [dns2 dns2-ip] peer-address
– これに対応したスクリプトで
設定ファイルにアドレスを書き込んで restart
まとめ
● vnet jail を使うことで、ハイパーバイザを使わない
でも
だけの構成で mpd5 + ipfw + サーバーいくつかと
いう環境をそれなりにネットワーク分離しつつ構築
できます。
● 面倒くさい割には、「無線LANルーター買ってくれ
ばいいんじゃね」という感じですが、趣味ですので。
1 of 15

Recommended

10+ Deploys Per Day: Dev and Ops Cooperation at Flickr by
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
10+ Deploys Per Day: Dev and Ops Cooperation at FlickrJohn Allspaw
1M views78 slides
いまさら聞けないPostgreSQL運用管理 by
いまさら聞けないPostgreSQL運用管理いまさら聞けないPostgreSQL運用管理
いまさら聞けないPostgreSQL運用管理Uptime Technologies LLC (JP)
37.8K views60 slides
Poudriere for-the-poor by
Poudriere for-the-poorPoudriere for-the-poor
Poudriere for-the-poorhoo0005
319 views8 slides
FreeBSDでおうちのルーター by
FreeBSDでおうちのルーターFreeBSDでおうちのルーター
FreeBSDでおうちのルーターhoo0005
2.3K views33 slides
ChatGPT and the Future of Work - Clark Boyd by
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
28K views69 slides
Getting into the tech field. what next by
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
6.6K views22 slides

More Related Content

Featured

Introduction to Data Science by
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
82.6K views51 slides
Time Management & Productivity - Best Practices by
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
169.8K views42 slides
The six step guide to practical project management by
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
36.7K views27 slides
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
12.7K views21 slides
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
55.5K views138 slides
12 Ways to Increase Your Influence at Work by
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
401.7K views64 slides

Featured(20)

Time Management & Productivity - Best Practices by Vit Horky
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky169.8K views
The six step guide to practical project management by MindGenius
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius36.7K views
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by RachelPearson36
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson3612.7K views
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.5K views
12 Ways to Increase Your Influence at Work by GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.7K views
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K views
Barbie - Brand Strategy Presentation by Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well by Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.3K views
Introduction to C Programming Language by Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.5K views
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... by Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.4K views
9 Tips for a Work-free Vacation by Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
How to Map Your Future by SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -... by AccuraCast
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
AccuraCast3.4K views
Exploring ChatGPT for Effective Teaching and Learning.pptx by Stan Skrabut, Ed.D.
Exploring ChatGPT for Effective Teaching and Learning.pptxExploring ChatGPT for Effective Teaching and Learning.pptx
Exploring ChatGPT for Effective Teaching and Learning.pptx
Stan Skrabut, Ed.D.57.7K views
How to train your robot (with Deep Reinforcement Learning) by Lucas García, PhD
How to train your robot (with Deep Reinforcement Learning)How to train your robot (with Deep Reinforcement Learning)
How to train your robot (with Deep Reinforcement Learning)
Lucas García, PhD42.5K views

FreeBSD でおうちのルーター (CBUG meeting 2014/05/17)

  • 1. FreeBSD でおうちのルーター vnet jail + mpd5 + ipfw とか cache DNS sever + 内部に閉じた private DNS 2014年5月17日 於 CBUG Meeting 小野 寛生
  • 3. 設定 ● vnet jail はとがわさんのページを参考にしました – http://toga.vegalta.org/wordpress/2013/10/08/481 ● mpd5 の設定はまきHikiを参考にしました – http://triaez.kaisei.org/~mzaki/hiki/?FreeBSD/ネットワーク ● ipfw (w/NAT) は man を読んでがんばりました – あとは、FreeBSD 6.x の頃に hrs さんに教えてもらった こととか – man を読むと、nat 以外にも not antispoof とか table とか {} で括れるとか
  • 4. vnet jail ● jail + ネットワークスタック分離 – (Solaris zone を目指した?) ● kernel config に options VIMAGE が必要 – まだ安定していないので GENERIC に入っていない – 最近 pf が host で使えるようになった
  • 5. VIMAGE (vnet) による分離の例 ● 通常の jail – 同じ interface が見える ● ifconfig -a ● jexec jname ifconfig -a ● vnet jail – interface は vnet (host と jail ごと) に所属する – 例 ● ifconfig epair0 create → host に epair0a, epair0b ● ifconfig epair0b vnet jname – ifconfig -a → epari0a だけ出てくる – jexec jname ifconfig -a → epair0b だけ出てくる
  • 6. 構成 (物理) EeeBox Intel(R) Atom(TM) CPU N270 RAM 2GB SSD 120GB くらい
  • 7. 構成 (ネットワーク?) mpd + ipfw ISP Flets Sq. bridge0 re0 ng0 ng1 SW hub epair3a epair0a ue0 epair0b ral0 客用AP epair2b epair3b epair1b epair1a outer inner gate 家用の無線 APもこっち re0 bridge1 forwarding 有効
  • 8. 何をしているか ● gate – mpd5 で ISP と Flets sq. に PPPoE 接続 – ipfw + nat でゲートウェイ&ファイアウォール – unbound で cache DNS server – sshd (の予定) ● inner – yadifad で 勝手 authoritative DNS server ● 勝手 = private IP に振っている – isc-dhcpd bridge はこれのための面も ● outer – 外向け httpd (の予定)
  • 9. ファイアウォール ● ipfw + nat – nat 10 ip from any to any via ng0 の形でないと NAT が通らなかった。 – NAT ルールの前に deny ip from any to 192.168.0.0/16 via {ue0,ng0,ng1} deny ip from 192.168.0.0/16 to any via {ue0,ng0,ng1} で (たぶん) 外から入り込まれるのを防げていると思う。
  • 10. VIMAGE (vnet) による分離 ● jexec gate netstat -a USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS unbound unbound 3449 3 udp4 192.168.8.1:53 *:* unbound unbound 3449 4 tcp4 192.168.8.1:53 *:* unbound unbound 3449 5 udp4 192.168.16.1:53 *:* unbound unbound 3449 6 tcp4 192.168.16.1:53 *:* unbound unbound 3449 9 udp6 *:53 *:* unbound unbound 3449 10 tcp6 *:53 *:* root sendmail 1511 4 tcp4 127.0.0.1:25 *:* root mpd5 1454 16 tcp6 ::1:5005 *:* root mpd5 1454 19 tcp4 *:5006 *:* root syslogd 1445 6 udp6 *:514 *:* root syslogd 1445 7 udp4 *:514 *:* ● tcp,udp はこれだけ。赤は設定漏れで外向けにも開いているもの ● あとは、外向けに sshd, http (redirect) を開ける予定
  • 11. ezjail + vnet の設定 ● ezjail じゃなくてもいいんですが – jail.conf 直とか qjail, qjail2 … とかあるみたいです。 ● /etc/rc.conf ezjail_enable=”YES” jail_parameters=”vnet=new” ● /usr/local/etc/ezjail/jailname ファイル – export_jname_ip=”0.0.0.0” (別途 ifconfig で) – export_jname_parameters=”allow_raw_sockets=1” – export_jname_parameters= ”allow_raw_sockets=1 vnet=new” mpd5 で必要 全体なら rc.conf 一部なら ezjail/* 別に
  • 12. ezjail + vnet の設定 (続き) ● /usr/local/etc/ezjail/jailname ファイル – export ezjail_jname_{pre,post}startN=... で ● ifconfig create epair0 up とか ● ifconfig ue0 vnet jname とか ● jexec jname ifconfig epair0b 192.168.0.2/24 とか – /etc/rc の実行 ● export ezjail_jname_exec_start=”” … ● export ezjail_jname_poststartN=”/bin/sh /etc/rc” – poststart の最後に書く – interface が設定された後に daemon が起動されるようにするため
  • 13. mpd.conf ● アドレスを取得したところで、ipfw と unbound を restart する – mpd.conf ● set iface up-script script-path で次の形式でスクリプトが起動される – up-script if proto local-ip remote-ip authname [dns1 dns1-ip] [dns2 dns2-ip] peer-address – これに対応したスクリプトで 設定ファイルにアドレスを書き込んで restart
  • 14. mpd.conf ● アドレスを取得したところで、ipfw と unbound を restart する – mpd.conf ● set iface up-script script-path で次の形式でスクリプトが起動される – up-script if proto local-ip remote-ip authname [dns1 dns1-ip] [dns2 dns2-ip] peer-address – これに対応したスクリプトで 設定ファイルにアドレスを書き込んで restart
  • 15. まとめ ● vnet jail を使うことで、ハイパーバイザを使わない でも だけの構成で mpd5 + ipfw + サーバーいくつかと いう環境をそれなりにネットワーク分離しつつ構築 できます。 ● 面倒くさい割には、「無線LANルーター買ってくれ ばいいんじゃね」という感じですが、趣味ですので。