両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン |
linux:commands:network:firewall-cmd [2022/09/20 12:23] – ともやん | linux:commands:network:firewall-cmd [2025/02/21 12:16] (現在) – [サービスで許可されるポートを調べる] ともやん |
---|
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo dnf install firewalld | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">dnf</font> install firewalld |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --list-all-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--list-all-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result_long><html><pre> | <WRAP color_result_long><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --list-all-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--list-all-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result_long><html><pre> | <WRAP color_result_long><html><pre> |
</WRAP> | </WRAP> |
| |
===== デフォルトゾーンの確認 ===== | ===== デフォルトゾーンとアクティブゾーンの確認 ===== |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-default-zone | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-default-zone</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</WRAP> | </WRAP> |
| |
<WRAP left round tip 95%> | <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-active-zones</font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| FedoraWorkstation |
| interfaces: wlp2s0 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP left round tip 95% minfont_12> |
はじめに__デフォルトゾーンの確認を行っておくことは重要__です。\\ | はじめに__デフォルトゾーンの確認を行っておくことは重要__です。\\ |
<html><code>firewall-cmd</code></html> コマンドを <html><code>--zone</code></html> オプションを省略して実行すると、すべての操作はデフォルトゾーンに対して行われます。\\ | <html><code>firewall-cmd</code></html> コマンドを <html><code>--zone</code></html> オプションを省略して実行すると、すべての操作はデフォルトゾーンに対して行われます。\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-default-zone | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-default-zone</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --list-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--list-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --zone=FedoraWorkstation --list-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--zone=FedoraWorkstation --list-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --zone=FedoraServer --list-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--zone=FedoraServer --list-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-default-zone | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-default-zone</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-active-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-active-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --zone=FedoraServer --change-interface=enp8s0 | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--zone=FedoraServer --change-interface=enp8s0</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-active-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-active-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --list-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--list-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
</WRAP> | </WRAP> |
| |
===== デフォルトゾーンの変更 ===== | ===== デフォルトゾーンとアクティブゾーンの変更 ===== |
workゾーンへ変更 | デフォルトゾーンを FedoraServer へ変更\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --set-default-zone=work | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--set-default-zone=FedoraServer</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | |
| |
すべてのアクセスを許可するtrustedゾーンへ変更 | |
<WRAP color_term> | |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --set-default-zone=trusted | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-default-zone</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| FedoraServer |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | |
※これらの変更はすぐに反映される。 | |
| |
===== アクティブゾーンの確認 ===== | |
<WRAP color_term> | |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-active-zones | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--get-active-zones</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
FedoraServer | FedoraWorkstation |
interfaces: br0 ens33 | interfaces: wlp2s0 |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| ※デフォルトゾーンを変更してもアクティブゾーンが変更される訳ではない🤔\\ |
===== アクティブゾーンの変更 ===== | これらの変更はすぐに反映される🤔\\ |
| \\ |
| アクティブゾーンを FedoraServer へ変更\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --zone=work --change-interface=ens33 | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd </font> <font color="#A347BA">--zone=FedoraServer --change-interface=wlp2s0</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
| </pre></html></WRAP> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd </font> <font color="#A347BA">--get-active-zones</font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| FedoraServer |
| interfaces: wlp2s0 |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --list-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--list-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --list-ports | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd </font> <font color="#A347BA">--list-ports</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --get-services | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd </font> <font color="#A347BA">--get-services</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --add-service=ssh | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --add-service=ssh</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --remove-service=ssh | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --remove-service=ssh</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
| </pre></html></WRAP> |
| </WRAP> |
| |
| 複数サービスの許可を一括で永続的に削除🤤\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--permanent</font> <font color="#A347BA">--remove-service=</font><font color="#12488B"><b>{</b></font><font color="#A347BA">ssh,cockpit</font><font color="#12488B"><b>}</b></font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --add-port=22022/tcp | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --add-port=22022/tcp</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --remove-port=22022/tcp | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --remove-port=22022/tcp</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --add-source=192.168.1.0/24 | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA"> --permanent --add-source=192.168.1.0/24</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --add-source=192.168.1.0/24 --zone=drop | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --add-source=192.168.1.0/24 --zone=drop</font> |
$ sudo firewall-cmd --permanent --add-source=192.168.1.1 --zone=drop | |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
| </pre></html></WRAP> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --add-source=192.168.1.1 --zone=drop</font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --list-sources --zone=drop | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--list-sources --zone=drop</font> |
192.168.1.0/24 192.168.1.1 | 192.168.1.0/24 192.168.1.1 |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --permanent --remove-source=192.168.1.0/24 --zone=drop | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --remove-source=192.168.1.0/24 --zone=drop</font> |
$ sudo firewall-cmd --permanent --remove-source=192.168.1.1 --zone=drop | <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo firewall-cmd</font> <font color="#A347BA">--permanent --remove-source=192.168.1.1 --zone=drop</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ sudo firewall-cmd --reload | <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--reload</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre> | <WRAP color_result><html><pre> |
| success |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ cat /usr/lib/firewalld/services/ldap.xml | <font color="#0087FF"><b>$</b></font> <font color="#26A269">bat</font> <u style="text-decoration-style:solid">/usr/lib/firewalld/services/ldap.xml</u> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| <font color="#444444"> 1</font> <font color="#FFFFFF"><?</font><font color="#F92672">xml</font><font color="#F8F8F2"> </font><font color="#A6E22E">version</font><font color="#F8F8F2">=</font><font color="#E6DB74">"1.0"</font><font color="#F8F8F2"> </font><font color="#A6E22E">encoding</font><font color="#F8F8F2">=</font><font color="#E6DB74">"utf-8"</font><font color="#FFFFFF">?></font> |
| <font color="#444444"> 2</font> <font color="#FFFFFF"><</font><font color="#F92672">service</font><font color="#FFFFFF">></font> |
| <font color="#444444"> 3</font> <font color="#F8F8F2"> </font><font color="#FFFFFF"><</font><font color="#F92672">short</font><font color="#FFFFFF">></font><font color="#F8F8F2">LDAP</font><font color="#FFFFFF"></</font><font color="#F92672">short</font><font color="#FFFFFF">></font> |
| <font color="#444444"> 4</font> <font color="#F8F8F2"> </font><font color="#FFFFFF"><</font><font color="#F92672">description</font><font color="#FFFFFF">></font><font color="#F8F8F2">Lightweight Directory Access Protocol (LDAP) server</font><font color="#FFFFFF"></</font><font color="#F92672">description</font><font color="#FFFFFF">></font> |
| <font color="#444444"> 5</font> <font color="#F8F8F2"> </font><font color="#FFFFFF"><</font><font color="#F92672">port</font><font color="#F8F8F2"> </font><font color="#A6E22E">protocol</font><font color="#F8F8F2">=</font><font color="#E6DB74">"tcp"</font><font color="#F8F8F2"> </font><font color="#A6E22E">port</font><font color="#F8F8F2">=</font><font color="#E6DB74">"389"</font><font color="#FFFFFF">/></font> |
| <font color="#444444"> 6</font> <font color="#FFFFFF"></</font><font color="#F92672">service</font><font color="#FFFFFF">></font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result> | |
<code xml> | |
<?xml version="1.0" encoding="utf-8"?> | |
<service> | |
<short>LDAP</short> | |
<description>Lightweight Directory Access Protocol (LDAP) server</description> | |
<port protocol="tcp" port="389"/> | |
</service> | |
</code></WRAP> | |
</WRAP> | </WRAP> |
| |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
$ firewall-cmd --help | <font color="#0087FF"><b>$</b></font> <font color="#26A269">firewall-cmd</font> <font color="#A347BA">--help</font> |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result_long><html><pre> | <WRAP color_result_long><html><pre> |