2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RaspiでNATルーターを構築する

Posted at

はじめに

Raspberry piでルーターを作ってみる

raspberrypi imagerの使用

sdカードにイメージを書き込む

sshの設定

sdカードに直接 → sshからファイルを作成する
raspi-config → sshのオン

無線の設定

無線のインターフェイス起動

以下を書きこむ
/etc/wpa_supplicant/wpa_supplicant.conf
country = JP

#rfkill unblock wifi
#ifconfig wlan0 up

DNSの設定

/etc/dhcpcd.conf

interface wlan0
static domain_name_servers=172.24.2.51

無線の認証設定

/etc/wpa_supplicant/wpa_supplicant.conf
country = JP
network={
ssid="media"
psk="metro-cit"
}

GUI起動設定

パッケージインストール

apt-get -y update
apt-get -y install lightdm

raspi-config
boot GUIを選択
interface → VNCの選択

有線設定

IP設定

/etc/dhcpcd.conf
interface eth0
static ip_address=192.168.0.254/24
static routers=0.0.0.0
static domain_name_servers=0.0.0.0

IPマスカレード(NAT)の設定

sudo apt-get install iptables-persistent

/etc/rc.local

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

exit 0

DHCPサーバーの設定

DHCPサーバーのインストール

sudo apt install -y isc-dhcp-server dnsmasq

コンフィグの書き換え

nano /etc/dhcp/dhcpd.conf

#option domain-name "example.org"; #コメントアウトする
#option domain-name-servers ns1.example.org, ns2.example.org; #コメントアウトする

authoritative; #コメントアウトを外す

#追記
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.199;
option routers 192.168.0.254;
option domain-name-servers 172.24.2.51;
option broadcast-address 192.168.0.255;
ignore declines;
}

インターフェイスの設定

/etc/default/isc-dhcp-server

INTERFACESv4="eth0"

サーバーの起動

sudo systemctl start isc-dhcp-server.service
sudo systemctl enable isc-dhcp-server.service

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?