「インターネット共有」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
 
26行目: 26行目:
 
== 設定 ==
 
== 設定 ==
   
  +
このセクションでは、クライアントのコンピュータに接続するネットワークデバイスの名前は '''''net0'''''、インターネットに接続するネットワークデバイスの名前は '''''internet0''''' としています。
This section assumes, that the network device connected to the client computer(s) is named '''''net0''''' and the network device connected to the internet as '''''internet0'''''.
 
   
  +
{{Tip|[[Udev#固定デバイス名の設定]]を使ってデバイスの名前は変更することができます。}}
{{Tip|You can rename your devices to this scheme using [[Udev#Setting static device names]].}}
 
   
 
=== 固定 IP アドレス ===
 
=== 固定 IP アドレス ===
   
  +
他のマシンに接続したインターフェイスに固定 IPv4 アドレスを割り当てます。アドレスの頭3バイトは他のインターフェイスのアドレスの頭3バイトと違っている必要があります。
Assign an static IPv4 address to the interface connected to the other machines. The first 3 bytes of this address cannot be exactly the same as those of another interface.
 
 
# ip link set up dev net0
 
# ip link set up dev net0
 
# ip addr add 192.168.123.100/24 dev net0 # arbitrary address
 
# ip addr add 192.168.123.100/24 dev net0 # arbitrary address
   
  +
起動時に固定 ip を割り当てたい場合、[[netctl]] を使います。
To have your static ip assigned at boot, you can use [[netctl]].
 
   
 
=== パケット転送の有効化 ===
 
=== パケット転送の有効化 ===
   
  +
現在のパケット転送の設定をチェック:
Check the current packet forwarding settings:
 
 
# sysctl -a | grep forward
 
# sysctl -a | grep forward
   
  +
次のコマンドを実行して一時的にパケット転送を有効化:
Enter this command to temporarily enable packet forwarding:
 
 
# sysctl net.ipv4.ip_forward=1
 
# sysctl net.ipv4.ip_forward=1
   
Edit {{ic|/etc/sysctl.d/30-ipforward.conf}} to make the previous change persistent after a reboot.
+
再起動した後も設定が残るようにするには {{ic|/etc/sysctl.d/30-ipforward.conf}} を編集:
 
{{hc|/etc/sysctl.d/30-ipforward.conf|<nowiki>
 
{{hc|/etc/sysctl.d/30-ipforward.conf|<nowiki>
 
net.ipv4.ip_forward=1
 
net.ipv4.ip_forward=1
55行目: 55行目:
 
=== NAT の有効化 ===
 
=== NAT の有効化 ===
   
[[pacman|Install]] the package {{Pkg|iptables}} from the [[official repositories]]. Use iptables to enable NAT:
+
[[公式リポジトリ]]から {{Pkg|iptables}} パッケージを[[インストール]]してください。iptables を使って NAT を有効化:
   
 
# iptables -t nat -A POSTROUTING -o internet0 -j MASQUERADE
 
# iptables -t nat -A POSTROUTING -o internet0 -j MASQUERADE
63行目: 63行目:
 
{{Note|Of course, this also works with a mobile broadband connection (usually called ppp0 on routing PC).}}
 
{{Note|Of course, this also works with a mobile broadband connection (usually called ppp0 on routing PC).}}
   
  +
詳細は [[iptables]] の記事を読んで下さい (特に、ルールの保存と、起動時に自動的にルールを適用させる方法の項)。iptables については[[シンプルなステートフルファイアウォール]]のページでも詳しい解説をしています。
Read the [[iptables]] article for more information (especially saving the rule and applying it automatically on boot). There is also an excellent guide on iptables [[Simple stateful firewall]].
 
   
 
=== クライアント PC に IP アドレスを割り当てる ===
 
=== クライアント PC に IP アドレスを割り当てる ===

2015年3月28日 (土) 07:25時点における版

関連記事

この記事ではあるマシンと他のマシンでインターネット接続を共有する方法を解説します。

要件

  • サーバーとして機能するマシンにはネットワークデバイスを別に設定する必要があります。
  • ネットワークデバイスはインターネットにアクセスするマシンと接続します。一つ、または複数のマシンを使うことができます。複数のマシンとインターネットを共有するにはスイッチが必要です。一つのマシンで共有する場合は、クロスオーバーケーブルで十分です。
ノート: If one of the two computers has a gigabit ethernet card, a crossover cable is not necessary and a regular ethernet cable should be enough

設定

このセクションでは、クライアントのコンピュータに接続するネットワークデバイスの名前は net0、インターネットに接続するネットワークデバイスの名前は internet0 としています。

ヒント: Udev#固定デバイス名の設定を使ってデバイスの名前は変更することができます。

固定 IP アドレス

他のマシンに接続したインターフェイスに固定 IPv4 アドレスを割り当てます。アドレスの頭3バイトは他のインターフェイスのアドレスの頭3バイトと違っている必要があります。

# ip link set up dev net0
# ip addr add 192.168.123.100/24 dev net0 # arbitrary address

起動時に固定 ip を割り当てたい場合、netctl を使います。

パケット転送の有効化

現在のパケット転送の設定をチェック:

# sysctl -a | grep forward

次のコマンドを実行して一時的にパケット転送を有効化:

# sysctl net.ipv4.ip_forward=1

再起動した後も設定が残るようにするには /etc/sysctl.d/30-ipforward.conf を編集:

/etc/sysctl.d/30-ipforward.conf
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1

NAT の有効化

公式リポジトリから iptables パッケージをインストールしてください。iptables を使って NAT を有効化:

# iptables -t nat -A POSTROUTING -o internet0 -j MASQUERADE
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i net0 -o internet0 -j ACCEPT
ノート: Of course, this also works with a mobile broadband connection (usually called ppp0 on routing PC).

詳細は iptables の記事を読んで下さい (特に、ルールの保存と、起動時に自動的にルールを適用させる方法の項)。iptables についてはシンプルなステートフルファイアウォールのページでも詳しい解説をしています。

クライアント PC に IP アドレスを割り当てる

If you are planning to regularly have several machines using the internet shared by this machine, then is a good idea to install a dhcp server.

You can read the dhcpd wiki article, to add a dhcp server. Then, install the dhcpcd client on every client pc.

If you are not planing to use this setup regularly, you can manually add an ip to each client instead.

手動で IP を追加

Instead of using dhcp, on each client pc, add an ip address and the default route:

# ip addr add 192.168.123.201/24 dev eth0  # arbitrary address, first three blocks must match the address from above
# ip link set up dev eth0
# ip route add default via 192.168.123.100 dev eth0   # same address as in the beginning

Configure a DNS server for each client, see resolv.conf for details.

That's it. The client PC should now have Internet.

トラブルシューティング

If you are able to connect the two PCs but cannot send data (for example, if the client PC makes a DHCP request to the server PC, the server PC receives the request and offers an IP to the client, but the client does not accept it, timing out instead), check that you don't have other Iptables rules interfering.

参照