LoginSignup
0
0

More than 3 years have passed since last update.

firewalldでSSHポートを変更

Last updated at Posted at 2019-12-29

はじめに

Firewalldのサービスファイルは以下の2つに配置される。

  1. /usr/lib/firewalld/services/
  2. /etc/firewalld/services/

1は事前に定義されたサービスファイルが配置されている。2はユーザーが新たに定義したサービスファイルを配置する。

SSHポートの変更

1のディレクトリ内に ssh.xml がある。これを直接編集するのも問題ないが、今回は2のディレクトリに新たにファイルを作成する。この方法だと既存の設定を上書きする形で設定をすることができる。

今回はSSHポートを TCP/20022 へポートを変更してみる。

$ sudo vi /etc/firewalld/services/ssh.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>SSH</short>
  <description>Secure Shell (SSH) is a protocol for logging into and executing ccommands on remote machines.</description>
  <port protocol="tcp" port="20022"/>
</service>

firewalldに読み込ませる。

$ sudo firewall-cmd --reload

sshd自体のlistenするポートの変更も忘れずに。 /etc/ssh/sshd_config を編集してsshdのrestartで適用させる。

補足:独自で作成したサービスを新たに登録する場合

firewalldで独自サービスを追加する方法

参考

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