「ルーター」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(en2:Routerへの転送ページ)
 
1行目: 1行目:
  +
[[Category:ネットワーク]]
#redirect[[en2:Router]]
 
  +
[[Category:セキュリティ]]
  +
[[en:Router]]
  +
{{Related articles start}}
  +
{{Related|シンプルなステートフルファイアウォール}}
  +
{{Related|インターネット共有}}
  +
{{Related articles end}}
  +
この記事ではコンピュータをインターネットゲートウェイ/ルーターに仕立てる方法を解説しています。ゲートウェイはインターネットに直接接続されるため、''セキュリティ''が重要です。外部からアクセスできるサービスを実行するのは好ましくありません。ゲートウェイとして機能するためのサービスだけを実行し、セキュリティ上の穴を作ってしまうおそれがある httpd, ftpd, samba, nfsd などは動かさないようにします。
  +
  +
クロスオーバーケーブルによる PC 間の接続の共有方法については扱っていません。インターネット共有をする方法は、[[インターネット共有]]を見て下さい。
  +
  +
==ハードウェアの要件==
  +
* 最低でも 1GB のディスク容量が必要です。ベースインストールは大体 500MB くらいですが、ウェブキャッシュプロキシなどを使うことを考えて、キャッシュ用に容量を確保しておく方が良いでしょう。
  +
* 最低でも2つの物理的なネットワークインターフェイスが必要です: ゲートウェイは2つのネットワークを相互に接続します。ネットワークは物理的に同一のコンピュータに接続する必要があります。インターフェイスの片方は外部のネットワークに接続し、もう片方は内部のネットワークに接続します。
  +
* ハブやスイッチ、UTP ケーブルが必要です: 他のコンピュータをゲートウェイに接続するための機器が必要です。
  +
  +
==ネットワークインターフェイスの名称==
  +
Conventions in this guide will be to use non-realistic interface names, to avoid confusion about which interface is which.
  +
  +
* '''intern0''': the network card connected to the LAN. On an actual computer it will probably have the name enp2s0, enp1s1, etc.
  +
* '''extern0''': the network card connected to the external network (or WAN). It will probably have the name enp2s0, enp1s1, etc.
  +
  +
==インストール==
  +
{{Note|完全なインストールガイドは、[[インストールガイド]]を見て下さい。}}
  +
  +
A fresh install of Arch Linux is the easiest to start from, as no configuration changes have been made and there is a minimal amount of packages installed. This is helpful when attempting to reduce security risk.
  +
  +
===パーティショニング===
  +
  +
For security purposes, {{ic|/var}}, {{ic|/tmp}} and {{ic|/home}} should be separate from the {{ic|/}} partition. This prevents disk space from being completely used up by log files, daemons or the unprivileged user. It also allows different mount options for those partitions. If you have already partitioned your drive, the [http://gparted.sourceforge.net/ gparted livecd] can be used to resize, move, or create new partitions.
  +
  +
Your home and root partitions can be much smaller than a regular install since this is not a desktop machine. {{ic|/var}} should be the largest partition—it is where databases, logs and long-term caches are stored. If you have a lot of RAM, mounting {{ic|/tmp}} as {{ic|tmpfs}} is a good idea, so making a disk partition for it during the initial install is unnecessary. Note that {{ic|/tmp}} is mounted as {{ic|tmpfs}} by default in Arch.
  +
  +
===インストール後の設定===
  +
通常ユーザーのアカウントを作成したら [[sudo]] をインストールして [[sudo#root ログインを無効化|root ログインを無効化]]することを推奨します。
  +
  +
==ネットワークインターフェイスの設定==
  +
  +
===永続的な命名とインターフェイス名の変更===
  +
Systemd は自動的にそれぞれのインターフェイスに一意なインターフェイス名を決めます。決められた名前は永続的で、再起動しても変わることはありません。インターフェイスの名前をユーザーフレンドリーな名前に変更したい場合は、[[ネットワーク設定#デバイス名]]を読んで下さい。
  +
  +
===IP の設定===
  +
Now you will need to configure the network interfaces. The best way to do so is using [[netctl]] profiles. You will need to create two profiles.
  +
{{Note|If you will be connecting to the Internet only via PPPoE (you have one WAN port) you '''do not need''' to setup or enable the extern0-profile. See below for more information on configuring PPPoE.}}
  +
* {{ic|/etc/netctl/extern0-profile}}
  +
Description='Public Interface.'
  +
Interface=extern0
  +
Connection=ethernet
  +
IP='dhcp'
  +
  +
* {{ic|/etc/netctl/intern0-profile}}
  +
Description='Private Interface'
  +
Interface=intern0
  +
Connection=ethernet
  +
IP='static'
  +
Address=('10.0.0.1/24')
  +
  +
{{Note|The example configuration above assumes a full subnet. If you are building the gateway for a small amount of people, you will want to change the CIDR suffix to accommodate a smaller range. For example /27 will give you 10.0.0.1 to 10.0.0.30. You can find many CIDR calculators online.}}
  +
  +
Next up is to set up the interfaces with netctl.
  +
# netctl enable extern0-profile
  +
# netctl enable intern0-profile
  +
  +
==ADSL 接続/PPPoE==
  +
rp-pppoe を使って、ファイアウォールの {{ic|extern0}} インターフェイスに ADSL モデムを接続して Arch で接続を管理することができます。モデムは''ブリッジ''モードに設定してください (ハーフブリッジまたは RFC1483)、そうしないとモデムもルーターとして機能してしまいます。{{pkg|rp-pppoe}} パッケージを[[インストール]]してください。
  +
  +
It should be noted that if you use only PPPoE to connect to the internet (ie. you do not have other WAN port, except for the one that connects to your modem) you do not need to set up the {{ic|extern0-profile}} as the external pseudo-interface will be ppp0.
  +
  +
===PPPoE の設定===
  +
You can use netctl to setup the pppoe connection. To get started
  +
# cp /etc/netctl/examples/pppoe /etc/netctl/
  +
and start editing. For the interface configuration choose the interface that connects to the modem. If you only connect to the internet through PPPoE this will probably be {{ic|extern0}}. Fill in the rest of the fields with your ISP information. See the pppoe section in netctl.profile man page for more information on the fields.
  +
  +
==DNS と DHCP==
  +
LAN のための DNS と DHCP デーモンとして [[dnsmasq]] を使います。dnsmasq は小規模なネットワーク用に設計されています。[[公式リポジトリ]]から {{Pkg|dnsmasq}} を[[pacman|インストール]]してください。
  +
  +
Dnsmasq needs to be configured to be a DHCP server. To do this:
  +
  +
Edit {{ic|/etc/dnsmasq.conf}}:
  +
  +
interface=intern0 # make dnsmasq listen for requests only on intern0 (our LAN)
  +
expand-hosts # add a domain to simple hostnames in /etc/hosts
  +
domain=foo.bar # allow fully qualified domain names for DHCP hosts (needed when
  +
# "expand-hosts" is used)
  +
dhcp-range=10.0.0.2,10.0.0.255,255.255.255.0,1h # defines a DHCP-range for the LAN:
  +
# from 10.0.0.2 to .255 with a subnet mask of 255.255.255.0 and a
  +
# DHCP lease of 1 hour (change to your own preferences)
  +
  +
Somewhere below, you will notice you can also add "static" DHCP leases, i.e. assign an IP-address to the MAC-address of a computer on the LAN. This way, whenever the computer requests a new lease, it will get the same IP. That is very useful for network servers with a DNS record. You can also deny certain MAC's from obtaining an IP.
  +
  +
Now start dnsmasq:
  +
# systemctl start dnsmasq.service
  +
  +
==接続の共有==
  +
  +
Time to tie the two network interfaces to each other.
  +
===iptables===
  +
[[シンプルなステートフルファイアウォール]]に [[iptables]] ファイアウォールと NAT の設定方法がまとまっています。
  +
  +
Make sure you added the firewall exceptions for DHCP and Domain, if you want to use Dnsmasq:
  +
  +
* Insert Rules:
  +
# iptables -t filter -I INPUT -i intern0 -p udp -m udp --dport 67 -j ACCEPT
  +
# iptables -t filter -I INPUT -i intern0 -p tcp -m tcp --dport 67 -j ACCEPT
  +
# iptables -t filter -I INPUT -i intern0 -p udp -m udp --dport 53 -j ACCEPT
  +
# iptables -t filter -I INPUT -i intern0 -p tcp -m tcp --dport 53 -j ACCEPT
  +
  +
===Shorewall===
  +
Shorewall, an iptables frontend, can be used as an easier alternative. See [[Shorewall]] for detailed configuration.
  +
  +
==不要なソフトウェアの削除==
  +
  +
Now that the installation has been performed, it is necessary to remove as many packages as possible. Since we are making a gateway, keeping unneeded packages only "bloats" the system, and increases the number of security risks.
  +
  +
First, check for obsolete/deprecated packages (likely after a fresh install and massive series of updates):
  +
  +
$ pacman -Qm
  +
  +
Review the list of explicitly installed packages that are not dependencies and remove any that are unneeded. Having only needed packages installed is an important security consideration.
  +
  +
$ pacman -Qet
  +
  +
Completely remove the packages you do not need along with their configuration files and dependencies:
  +
  +
# pacman -Rsn package1 package2 package3
  +
  +
== Logrotate ==
  +
  +
[[logrotate]] の設定を確認して、ログを保存するためのディスク容量が足りなくなってルーターが落ちてしまわないようにしてください。
  +
  +
Logrotate はデフォルトでインストールされるため、別個にインストールする必要はありません。
  +
  +
==その他の設定==
  +
  +
===UPnP===
  +
The above configuration of shorewall does not include [[Wikipedia:UPnP|UPnP]] support. Use of UPnP is discouraged as it may make the gateway vulnerable to attacks from within the LAN. However, some applications require this to function correctly.
  +
  +
ルーターで UPnP を有効にするには、UPnP インターネットゲートウェイデーモン (IGD) をインストールする必要があります。[[公式リポジトリ]]から {{Pkg|miniupnpd}} をインストールしてください。
  +
  +
詳細は [http://www.shorewall.net/UPnP.html Shorewall guide on UPnP] を読んで下さい。
  +
  +
===リモート管理===
  +
  +
[[OpenSSH]] を使うことでルーターをリモートで管理することができます。"ヘッドレス" (モニタや入力デバイスを接続しない) に動かしたいときに有用です。
  +
  +
=== ウェブキャッシュプロキシ ===
  +
  +
ブラウジングを高速化したりセキュリティを高めるためにウェブプロキシを設定する方法は [[Squid]] や [[Polipo]] を見て下さい。
  +
  +
=== 時刻サーバー ===
  +
ルーターを時刻サーバーとして使いたい場合、[[Network Time Protocol daemon]] を見て下さい。
  +
  +
Then, configure shorewall or iptables to allow NTP traffic in and out.
  +
  +
=== コンテンツフィルタリング ===
  +
  +
コンテンツフィルタリングが必要なときは [[DansGuardian]] や [[Privoxy]] をインストール・設定してください。
  +
  +
=== トラフィックシェーピング ===
  +
  +
Traffic shaping is very useful, especially when you are not the only one on the LAN. The idea is to assign a priority to different types of traffic. Interactive traffic (ssh, online gaming) probably needs the highest priority, while P2P traffic can do with the lowest. Then there is everything in between.
  +
  +
==== shorewall によるトラフィックシェーピング ====
  +
  +
[http://www.shorewall.net/traffic_shaping.htm Shorewall's Traffic Shaping/Control] ガイドを読んで下さい。
  +
  +
Here is my config as an example:
  +
* /etc/shorewall/tcdevices : here is where you define the interface you want to have shaped and its rates. I have got a ADSL connection with a 4MBit down/256KBit up profile.
  +
ppp0 4mbit 256kbit
  +
* /etc/shorewall/tcclasses : here you define the minimum (rate) and maximum (ceil) throughput per class. You will assign each one to a type of traffic to shape.
  +
# interactive traffic (ssh)
  +
ppp0 1 full full 0
  +
# online gaming
  +
ppp0 2 full/2 full 5
  +
# http
  +
ppp0 3 full/4 full 10
  +
# rest
  +
ppp0 4 full/6 full 15 default
  +
* /etc/shorewall/tcrules : this file contains the types of traffic and the class it belongs to.
  +
1 0.0.0.0/0 0.0.0.0/0 tcp ssh
  +
2 0.0.0.0/0 0.0.0.0/0 udp 27000:28000
  +
3 0.0.0.0/0 0.0.0.0/0 tcp http
  +
3 0.0.0.0/0 0.0.0.0/0 tcp https
  +
I have split it up my traffic in 4 groups:
  +
# interactive traffic or ssh: although it takes up almost no bandwidth, it is very annoying if it lags due to leechers on the LAN. This get the highest priority.
  +
# online gaming: needless to say you ca not play when your ping sucks. ;)
  +
# webtraffic: can be a bit slower
  +
# everything else: every sort of download, they are the cause of the lag anyway.
  +
  +
===snort による侵入検知===
  +
  +
[[Snort]] を見て下さい。

2015年7月12日 (日) 14:19時点における版

関連記事

この記事ではコンピュータをインターネットゲートウェイ/ルーターに仕立てる方法を解説しています。ゲートウェイはインターネットに直接接続されるため、セキュリティが重要です。外部からアクセスできるサービスを実行するのは好ましくありません。ゲートウェイとして機能するためのサービスだけを実行し、セキュリティ上の穴を作ってしまうおそれがある httpd, ftpd, samba, nfsd などは動かさないようにします。

クロスオーバーケーブルによる PC 間の接続の共有方法については扱っていません。インターネット共有をする方法は、インターネット共有を見て下さい。

ハードウェアの要件

  • 最低でも 1GB のディスク容量が必要です。ベースインストールは大体 500MB くらいですが、ウェブキャッシュプロキシなどを使うことを考えて、キャッシュ用に容量を確保しておく方が良いでしょう。
  • 最低でも2つの物理的なネットワークインターフェイスが必要です: ゲートウェイは2つのネットワークを相互に接続します。ネットワークは物理的に同一のコンピュータに接続する必要があります。インターフェイスの片方は外部のネットワークに接続し、もう片方は内部のネットワークに接続します。
  • ハブやスイッチ、UTP ケーブルが必要です: 他のコンピュータをゲートウェイに接続するための機器が必要です。

ネットワークインターフェイスの名称

Conventions in this guide will be to use non-realistic interface names, to avoid confusion about which interface is which.

  • intern0: the network card connected to the LAN. On an actual computer it will probably have the name enp2s0, enp1s1, etc.
  • extern0: the network card connected to the external network (or WAN). It will probably have the name enp2s0, enp1s1, etc.

インストール

ノート: 完全なインストールガイドは、インストールガイドを見て下さい。

A fresh install of Arch Linux is the easiest to start from, as no configuration changes have been made and there is a minimal amount of packages installed. This is helpful when attempting to reduce security risk.

パーティショニング

For security purposes, /var, /tmp and /home should be separate from the / partition. This prevents disk space from being completely used up by log files, daemons or the unprivileged user. It also allows different mount options for those partitions. If you have already partitioned your drive, the gparted livecd can be used to resize, move, or create new partitions.

Your home and root partitions can be much smaller than a regular install since this is not a desktop machine. /var should be the largest partition—it is where databases, logs and long-term caches are stored. If you have a lot of RAM, mounting /tmp as tmpfs is a good idea, so making a disk partition for it during the initial install is unnecessary. Note that /tmp is mounted as tmpfs by default in Arch.

インストール後の設定

通常ユーザーのアカウントを作成したら sudo をインストールして root ログインを無効化することを推奨します。

ネットワークインターフェイスの設定

永続的な命名とインターフェイス名の変更

Systemd は自動的にそれぞれのインターフェイスに一意なインターフェイス名を決めます。決められた名前は永続的で、再起動しても変わることはありません。インターフェイスの名前をユーザーフレンドリーな名前に変更したい場合は、ネットワーク設定#デバイス名を読んで下さい。

IP の設定

Now you will need to configure the network interfaces. The best way to do so is using netctl profiles. You will need to create two profiles.

ノート: If you will be connecting to the Internet only via PPPoE (you have one WAN port) you do not need to setup or enable the extern0-profile. See below for more information on configuring PPPoE.
  • /etc/netctl/extern0-profile
Description='Public Interface.'
Interface=extern0
Connection=ethernet
IP='dhcp'
  • /etc/netctl/intern0-profile
Description='Private Interface'
Interface=intern0
Connection=ethernet
IP='static'
Address=('10.0.0.1/24')
ノート: The example configuration above assumes a full subnet. If you are building the gateway for a small amount of people, you will want to change the CIDR suffix to accommodate a smaller range. For example /27 will give you 10.0.0.1 to 10.0.0.30. You can find many CIDR calculators online.

Next up is to set up the interfaces with netctl.

# netctl enable extern0-profile
# netctl enable intern0-profile

ADSL 接続/PPPoE

rp-pppoe を使って、ファイアウォールの extern0 インターフェイスに ADSL モデムを接続して Arch で接続を管理することができます。モデムはブリッジモードに設定してください (ハーフブリッジまたは RFC1483)、そうしないとモデムもルーターとして機能してしまいます。rp-pppoe パッケージをインストールしてください。

It should be noted that if you use only PPPoE to connect to the internet (ie. you do not have other WAN port, except for the one that connects to your modem) you do not need to set up the extern0-profile as the external pseudo-interface will be ppp0.

PPPoE の設定

You can use netctl to setup the pppoe connection. To get started

# cp /etc/netctl/examples/pppoe /etc/netctl/

and start editing. For the interface configuration choose the interface that connects to the modem. If you only connect to the internet through PPPoE this will probably be extern0. Fill in the rest of the fields with your ISP information. See the pppoe section in netctl.profile man page for more information on the fields.

DNS と DHCP

LAN のための DNS と DHCP デーモンとして dnsmasq を使います。dnsmasq は小規模なネットワーク用に設計されています。公式リポジトリから dnsmasqインストールしてください。

Dnsmasq needs to be configured to be a DHCP server. To do this:

Edit /etc/dnsmasq.conf:

interface=intern0 # make dnsmasq listen for requests only on intern0 (our LAN)
expand-hosts      # add a domain to simple hostnames in /etc/hosts
domain=foo.bar    # allow fully qualified domain names for DHCP hosts (needed when
                  # "expand-hosts" is used)
dhcp-range=10.0.0.2,10.0.0.255,255.255.255.0,1h # defines a DHCP-range for the LAN: 
                  # from 10.0.0.2 to .255 with a subnet mask of 255.255.255.0 and a
                  # DHCP lease of 1 hour (change to your own preferences)

Somewhere below, you will notice you can also add "static" DHCP leases, i.e. assign an IP-address to the MAC-address of a computer on the LAN. This way, whenever the computer requests a new lease, it will get the same IP. That is very useful for network servers with a DNS record. You can also deny certain MAC's from obtaining an IP.

Now start dnsmasq:

# systemctl start dnsmasq.service

接続の共有

Time to tie the two network interfaces to each other.

iptables

シンプルなステートフルファイアウォールiptables ファイアウォールと NAT の設定方法がまとまっています。

Make sure you added the firewall exceptions for DHCP and Domain, if you want to use Dnsmasq:

  • Insert Rules:
  # iptables -t filter -I INPUT -i intern0 -p udp -m udp --dport 67 -j ACCEPT
  # iptables -t filter -I INPUT -i intern0 -p tcp -m tcp --dport 67 -j ACCEPT
  # iptables -t filter -I INPUT -i intern0 -p udp -m udp --dport 53 -j ACCEPT
  # iptables -t filter -I INPUT -i intern0 -p tcp -m tcp --dport 53 -j ACCEPT

Shorewall

Shorewall, an iptables frontend, can be used as an easier alternative. See Shorewall for detailed configuration.

不要なソフトウェアの削除

Now that the installation has been performed, it is necessary to remove as many packages as possible. Since we are making a gateway, keeping unneeded packages only "bloats" the system, and increases the number of security risks.

First, check for obsolete/deprecated packages (likely after a fresh install and massive series of updates):

$ pacman -Qm

Review the list of explicitly installed packages that are not dependencies and remove any that are unneeded. Having only needed packages installed is an important security consideration.

$ pacman -Qet

Completely remove the packages you do not need along with their configuration files and dependencies:

# pacman -Rsn package1 package2 package3

Logrotate

logrotate の設定を確認して、ログを保存するためのディスク容量が足りなくなってルーターが落ちてしまわないようにしてください。

Logrotate はデフォルトでインストールされるため、別個にインストールする必要はありません。

その他の設定

UPnP

The above configuration of shorewall does not include UPnP support. Use of UPnP is discouraged as it may make the gateway vulnerable to attacks from within the LAN. However, some applications require this to function correctly.

ルーターで UPnP を有効にするには、UPnP インターネットゲートウェイデーモン (IGD) をインストールする必要があります。公式リポジトリから miniupnpd をインストールしてください。

詳細は Shorewall guide on UPnP を読んで下さい。

リモート管理

OpenSSH を使うことでルーターをリモートで管理することができます。"ヘッドレス" (モニタや入力デバイスを接続しない) に動かしたいときに有用です。

ウェブキャッシュプロキシ

ブラウジングを高速化したりセキュリティを高めるためにウェブプロキシを設定する方法は SquidPolipo を見て下さい。

時刻サーバー

ルーターを時刻サーバーとして使いたい場合、Network Time Protocol daemon を見て下さい。

Then, configure shorewall or iptables to allow NTP traffic in and out.

コンテンツフィルタリング

コンテンツフィルタリングが必要なときは DansGuardianPrivoxy をインストール・設定してください。

トラフィックシェーピング

Traffic shaping is very useful, especially when you are not the only one on the LAN. The idea is to assign a priority to different types of traffic. Interactive traffic (ssh, online gaming) probably needs the highest priority, while P2P traffic can do with the lowest. Then there is everything in between.

shorewall によるトラフィックシェーピング

Shorewall's Traffic Shaping/Control ガイドを読んで下さい。

Here is my config as an example:

  • /etc/shorewall/tcdevices : here is where you define the interface you want to have shaped and its rates. I have got a ADSL connection with a 4MBit down/256KBit up profile.
ppp0        4mbit        256kbit 
  • /etc/shorewall/tcclasses : here you define the minimum (rate) and maximum (ceil) throughput per class. You will assign each one to a type of traffic to shape.
# interactive traffic (ssh)
ppp0            1       full    full    0
# online gaming
ppp0            2       full/2  full    5
# http
ppp0            3       full/4  full    10
# rest
ppp0            4       full/6  full    15              default
  • /etc/shorewall/tcrules : this file contains the types of traffic and the class it belongs to.
1       0.0.0.0/0       0.0.0.0/0       tcp     ssh
2       0.0.0.0/0       0.0.0.0/0       udp     27000:28000
3       0.0.0.0/0       0.0.0.0/0       tcp     http
3       0.0.0.0/0       0.0.0.0/0       tcp     https

I have split it up my traffic in 4 groups:

  1. interactive traffic or ssh: although it takes up almost no bandwidth, it is very annoying if it lags due to leechers on the LAN. This get the highest priority.
  2. online gaming: needless to say you ca not play when your ping sucks. ;)
  3. webtraffic: can be a bit slower
  4. everything else: every sort of download, they are the cause of the lag anyway.

snort による侵入検知

Snort を見て下さい。