シェルスクリプトマガジン

特集1 自宅で本格ネットワーク環境構築(Vol.98記載)

著者:麻生 二郎

スマートフォンやパソコン、スマート家電をインターネットに接続するだけなら市販のルーターを購入するだけでよいでしょう。サーバーソフト、ネットワーク関連のソフトや機器を使ってみたい,試してみたい場合、普段使うネットワークとは分離した環境を用意しておくと便利です。本特集では、そのようなネットワーク環境を構築します。

シェルスクリプトマガジン Vol.98は以下のリンク先でご購入できます。

図16 /etc/hostapd/hostapd.confファイルの設定例

interface=wlan0
driver=nl80211
ssid=shmagtoku1
hw_mode=g
channel=6
auth_algs=1
wpa=2
wpa_passphrase=shmag202510t1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
country_code=JP
ieee80211d=1

図17 /etc/dnsmasq.d/dhcp.confファイルの設定例

interface=wlan0
dhcp-range=192.168.2.2,192.168.2.50,12h
domain-needed
bogus-priv

図18 /etc/network/interfacesファイルの設定例

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0

図19 /etc/nftables.d/router.nftファイルの設定例

table inet filter {
    chain input {
        type filter hook input priority 0;
        policy accept;
    }
    chain forward {
        type filter hook forward priority 0;
        policy accept;
    }
    chain output {
        type filter hook output priority 0;
        policy accept;
    }
}

table ip nat {
    chain postrouting {
        type nat hook postrouting priority 100;
        oifname "eth0" masquerade
    }
}

図20 /etc/dnsmasq.d/host.confの設定例

dhcp-option=option:dns-server,192.168.2.1
domain=home.localnet
local=/home.localnet/

dhcp-host=00:11:22:33:44:55,web,192.168.2.100
dhcp-host=00:22:33:44:55:66,file,192.168.2.120