LoginSignup
2
0

More than 3 years have passed since last update.

CentOSで起動時にサービスが起動するように設定する方法

Posted at
  • 環境
    • CentOS release 6.9 (Final)
    • iptables v1.4.7
    • chkconfig version 1.3.49.5

やりたいこと : CentOS6で起動したらiptablesを自動で起動できるようにしたい

AWSのインスタンスにiptablesでポートフォワードを設定した。
次の日、ローカルのWindowsからポートフォワード先に接続しようとした、が、つながらなかった。インスタンス起動しているのになぜ?それはiptablesが起動していないから。
インスタンスを起動するたびにiptablesを起動するのはつらいので、自動起動がいい。

# iptablesが起動していない
$ sudo service iptables status
iptables: Firewall is not running.

SysV Init系の起動プロセスに設定する

現状を確認する

参考 : chkconfig - サービスの自動起動の設定 / CentOS - Qiita

# サービスの状態を確認する
$ chkconfig --list iptables
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off

サービスの一覧に表示されていない場合は追加する

# サービスの一覧に表示されていない場合は
$ chkconfig --list
# 追加する
$ chkconfig --add iptables

サービスの自動起動を設定する

# 設定時のフォーマット
$ chkconfig [--level {ランレベル}] {サービス} on
# --listが見られるからって権限があるとは限らない
$ chkconfig iptables on
You do not have enough privileges to perform this operation.
# 自動起動を設定する
$ sudo chkconfig iptables on
# 確認する
$ chkconfig --list iptables
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
2
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
2
0