goo blog サービス終了のお知らせ 

情報技術の四方山話

AI、IoT、ヤマハルータ、VPN、無線LAN、Linux、クラウド、仮想サーバと情報セキュリティのよもやま話

UbuntuでLinuxルーター:実装編

2008-07-07 07:36:15 | Linux/Ubuntu
こんにちは。匠技術研究所の谷山 亮治です。


前回に引き続き、Linux/Ubuntuルーターの設定の仕方です。単純な「ローカルルーター」の設定を紹介します。Ubuntu以外のLinuxの設定例としても役立ちます。

UbuntuでLinuxルーター:方針編

◆ネットワーク構成図


[1]Ethernetカードの設定を確認する
Ubuntu7にはeth0とeth10がインストールされています。この二枚はeth0がオンボード、eth10は拡張です。どちらもUbuntu7からの自動認識で使っており、番号はLinux/Ubuntuが自動的に付番したものです。eth10のIP設定は、GNOMEを立ち上げシステム管理機能のGUIで行いました。もちろん、viエディタなどで、ファイルを直接変更することもできます。

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.32.20
netmask 255.255.255.0
gateway 192.168.32.1

auto eth0

iface eth10 inet static
address 192.168.0.5
netmask 255.255.255.0

auto eth10

[2]Linuxカーネルのルータ機能を設定する
今回のポイントはここです。Ubuntu7とUbuntu8では設定ファイルの記述が異なりますが、ポイントは全く同じです。/etc/sysctl.confに予め記述済みのルータ設定がコメントとなっています。コメントを外し、ルーター機能を使うようにします。

$ sudo vi /etc/sysctl.conf

[2.1]Ubuntu8での設定
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
net.ipv4.ip_forward=1

[2.2]Ubuntu7での設定
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.forwarding=1

[3]ルーター設定を反映する
sysctlコマンドで変更した/etc/sysctl.confを再読み込みし、ルーター機能を動かします。

$ sudo sysctl -p

[4]Ethernet設定を反映する
Linuxのnetworkの部分を再起動し、Ethernetの設定を反映します。この際、一時的にEternetが停止します。そのためローカルコンソールで実行しました。

$ sudo /etc/init.d/networking restart


Linux/Ubuntu7ルーターの設定はここまでです。ただこの時点では、ネットワーク全体が正しく設定されていないので、セグメントを越えた期待の動作はできません。あくまで「ルーターができた」というところです。

以下の手順で、設定が反映できたことを確認します。

[5]確認
[5.1] Ethernetインターフェース
Ethernetインターフェースの状況を確認します。IPアドレスが付番されていることを確認してください。IPアドレスが無くてもインターフェイスが起動していれば、表示されます。

$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4D:7E:3D:AA
inet addr:192.168.32.20 Bcast:192.168.32.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4dff:fe7e:3daa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11449 errors:0 dropped:0 overruns:0 frame:0
TX packets:14078 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1195700 (1.1 MB) TX bytes:3300492 (3.1 MB)
Interrupt:18 Base address:0x8000

eth10 Link encap:Ethernet HWaddr 00:50:43:00:19:60
inet addr:192.168.0.5 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:43ff:fe00:1960/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14678 errors:0 dropped:0 overruns:0 frame:0
TX packets:7206 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2352802 (2.2 MB) TX bytes:576867 (563.3 KB)
Interrupt:20

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)

[5.2]ルータ機能の反映確認
途中エラーがでますが、気にする必要はありません。Ubuntu8/Ubuntu7では表示が少し違うかもしれません。
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.eth0.forwarding = 1
net.ipv4.conf.eth10.forwarding = 1
の各行が”0”から"1"に変更になります。

$ sudo sysctl -A | grep forwarding
error: permission denied on key 'net.ipv4.route.flush'
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.all.mc_forwarding = 0
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.default.mc_forwarding = 0
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.lo.mc_forwarding = 0
net.ipv4.conf.eth0.forwarding = 1
net.ipv4.conf.eth0.mc_forwarding = 0
net.ipv4.conf.eth10.forwarding = 1
net.ipv4.conf.eth10.mc_forwarding = 0
error: permission denied on key 'net.ipv6.route.flush'
net.ipv6.conf.lo.forwarding = 0
net.ipv6.conf.eth0.forwarding = 0
net.ipv6.conf.all.forwarding = 0
net.ipv6.conf.default.forwarding = 0
net.ipv6.conf.eth10.forwarding = 0
error: permission denied on key 'dev.parport.parport0.autoprobe'
error: permission denied on key 'dev.parport.parport0.autoprobe0'
error: permission denied on key 'dev.parport.parport0.autoprobe1'
error: permission denied on key 'dev.parport.parport0.autoprobe2'
error: permission denied on key 'dev.parport.parport0.autoprobe3'
$

[5.3]ルーティングの確認
ルーティングが正しく設定できていることを確認します。インターネットに向かう側は、192.168.32.0/24のセグメントなので、デフォルトゲートウエイが192.168.32.1に向いています。このゲートウエイはKDDI ひかりOneについてくるホームゲートウエイです。

$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.32.0 * 255.255.255.0 U 0 0 0 eth0
192.168.0.0 * 255.255.255.0 U 0 0 0 eth10
link-local * 255.255.0.0 U 1000 0 0 eth0
default 192.168.32.1 0.0.0.0 UG 100 0 0 eth0
$

繰り返しになりますが、以上の設定だけではセグメント間通信はできません。ネットワーク設計をして、それぞれのセグメントへの経路情報を端末に伝える必要があります。

(*)この記事はLinux/Ubuntu8とFirefox3で作成しました。
(*)Windows環境を使うことなく画像を製作・加工しています。
(*)図表の作成はOpenOffice.org/Impress(PowerPoint相当)で行いました。
(*)図表はPNG出力し、GIMP画像編集ソフトで縮小しています。

☆匠ヤマハルータRT58i/RTX設定講習会7月開催分のお知らせ
☆中小企業のIT活用に関する、ご質問・ご相談はお気軽にどうぞ!

FoxkehFirefox3の現在のダウンロード数はこちら Firefox3の灯火へ

Firefox meter なかのひと
コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« UbuntuでLinuxルーター:方針編 | トップ | FirefoxがInternet Explorer... »
最新の画像もっと見る

コメントを投稿

サービス終了に伴い、10月1日にコメント投稿機能を終了させていただく予定です。
ブログ作成者から承認されるまでコメントは反映されません。

Linux/Ubuntu」カテゴリの最新記事