0
0

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.

CentOS8で簡易ルーターを作成する手順

Last updated at Posted at 2020-07-08

はじめに

この手順は何?

独立したセグメントを作りたかったので簡易ルーターが必要になった。
その時に作った簡易ルーターの作成手順+補足

作成環境

ルーターになるサーバーにCentOS8.2を最小構成でインストール
NICは必要なセグメント数分用意してそれぞれ必要に応じたIPアドレスを設定
※VyOSとかでも良かったけどセグメント分けられれば良かっただけなので、とりあえずCentOS8で作った。
※多分CentOS7でも同じ手順で動くと思う。

1.カーネルパラメタ設定

# cat << EOF > /etc/sysctl.d/router.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 1
EOF

# sysctl --system

※「net.ipv4.ip_forward = 1」はパケットのフォワードを許可
※「net.ipv4.conf.all.rp_filter = 1」スプーフィング(プライベートアドレスの詐称)対策

2.firewalldをiptablesに切り替え

※切り替えは必須ではないので手順省略は可

# systemctl stop firewalld
# systemctl disable firewalld
# yum install -y iptables-services
# systemctl enable iptables
# systemctl enable ip6tables
# systemctl restart iptables
# systemctl restart ip6tables

3.iptablesのルールの修正

※firewalldの場合はfirewalld-cmd等で同等の内容を実施

3.1.ルールのバックアップ

# cp -p /etc/sysconfig/{iptables,iptables_bak}

3.2.ルールの修正

※ルーターとなるサーバ自体へのアクセスルール(INPUT)は変えない。(変える必要があれば必要に応じて実施)
 パケットの転送(FORWARD)を破棄から許可に変更する。

# vi /etc/sysconfig/iptables

以下を修正
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
  ↓
-A FORWARD -j ACCEPT

3.3.ルールの反映

# systemctl restart iptables

4.必要に応じてルーティングを設定

nmtui、nmcli 等を使用して必要に応じてルーティングを設定

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?