本文链接: https://xiets.blog.csdn.net/article/details/123076750
Linux 网络 (ifconfig , ping , netstat ) 相关命令,参考:Linux 系统管理命令:时间、进程、网络、磁盘、关机重启等
刚买到的云主机,能 ping 通,主机后台的防火墙也开放了相关端口,SSH 也能连接,其他端口却无法访问,可能是 Linux 系统本身默认开启了防火墙 (默认只开放了 22 端口),需要添加防火墙端口规则或禁用系统的防火墙。
1. Ubuntu
Ubuntu (18+) 防火墙管理命令为 ufw ,官方文档。
帮助 信息:
$ ufw --help
Usage: ufw COMMAND
Commands:
enable enables the firewall
disable disables the firewall
default ARG set default policy
logging LEVEL set logging to LEVEL
allow ARGS add allow rule
deny ARGS add deny rule
reject ARGS add reject rule
limit ARGS add limit rule
delete RULE|NUM delete RULE
insert NUM RULE insert RULE at NUM
prepend RULE prepend RULE
route RULE add route RULE
route delete RULE|NUM delete route RULE
route insert NUM RULE insert route RULE at NUM
reload reload firewall
reset reset firewall
status show firewall status
status numbered show firewall status as numbered list of RULES
status verbose show verbose firewall status
show ARG show firewall report
version display version information
Application profile commands:
app list list application profiles
app info PROFILE show information on PROFILE
app update PROFILE update PROFILE
app default ARG set default application policy
启用 / 禁用 / 重新加载 防火墙:ufw enable|disable|reload
$ ufw enable
$ ufw disable
$ ufw reload
查看 防火墙状态 和 端口开启情况: ufw status
$ ufw status
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
开放 端口: ufw allow port[/protocol]
$ ufw allow 80
$ ufw allow 8000/tcp
$ ufw allow 8080/udp
删除 防火墙规则: ufw delete RULE|NUM
$ ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] 22 ALLOW IN Anywhere
[ 2] 80 ALLOW IN Anywhere
[ 3] 8000/tcp ALLOW IN Anywhere
[ 4] 8080/udp ALLOW IN Anywhere
[ 5] 22 (v6) ALLOW IN Anywhere (v6)
[ 6] 80 (v6) ALLOW IN Anywhere (v6)
[ 7] 8000/tcp (v6) ALLOW IN Anywhere (v6)
[ 8] 8080/udp (v6) ALLOW IN Anywhere (v6)
$ ufw delete 4
2. CentOS
CentOS (7+) 防火墙管理命令为 firewall-cmd ,相关网站。
查看 防火墙状态:
$ firewall-cmd --state
running
开放 / 关闭 端口:
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --zone=public --add-port=8000-8888/udp --permanent
$ firewall-cmd --zone=public --remove-port=80/tcp --permanent
$ firewall-cmd --reload
$ firewall-cmd --list-ports
启用 / 禁用、启动 / 停止 防火墙服务:
$ systemctl enable firewalld
$ systemctl disable firewalld
$ systemctl is-enabled firewalld
$ systemctl start firewalld
$ systemctl stop firewalld
$ systemctl status firewalld
|