LoginSignup
89

More than 5 years have passed since last update.

CentOS7でのiptablesの設定忘れるのでメモ

Posted at

毎回毎回調べるのも苦痛になってきたので、ここいらでメモ残しとく。

firewalldは全然つつけてないのと、つい見慣れてるiptablesのほうを使ってしまうんです。。。

firewalldを停止

command
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

iptablesのインストール

無ければインストールする

command
yum -y install iptables-services

iptablesの起動と自動起動の設定

command
systemctl start iptables
systemctl enable iptables
systemctl status iptables

iptablesの設定

vi /etc/sysconfig/iptables

iptables
*filter
:INPUT   DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT  ACCEPT [0:0]
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
# SSH
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# httpd
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# httpd ssl
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

SSHのポートを変更したら、SSHDのコンフィグも設定変更すること。
これを地味に忘れてて、1時間もハマってしまったので

vi /etc/ssh/sshd_config

sshd_config
#Port 22 ← コメントアウトを解除
Port 22

ポート番号変更したらsshdのリロードを行う

command
systemctl reload sshd

ちょっとしたサーバー立てた時に設定覚えてないの。

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
89