欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Linux 防火墙,阿里云安全组(上)|学习笔记

最编程 2024-08-11 14:36:34
...

开发者学堂课程【Linux 操作系统实战Linux 防火墙,阿里云安全组(上)】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/699/detail/12301


Linux 防火墙,阿里云安全组(上)


内容介绍

一、iptables 防火墙

二、firewall 防火墙

配置 Linux 防火墙规则的时候,一定要了解服务器开放的服务并进行正确配置,否则配置不当会影响正常访问服务,甚至不能远程登录管理服务器。


一、iptables 防火墙(Linux 6.x 及以下版本)

1.基本操作

#查看防火墙状态:service iptables status

# 停止防火墙:service iptables stop

# 启动防火墙:service iptables start

# 重启防火墙:service iptables restart

# 永久关闭防火墙:chkconfig iptables off

# 永久关闭后重启:chkconfig iptables on

  • 实际操作

(1)登陆服务器,查看版本(cat 命令)

image.png

(2)查看具体内容

cat/etc/sysconfig/iptables

包括进入端口、转发端口、输出端口、配置端口的信息。

image.png


(3)查看防火墙设置的规则

service iptables status

image.png

2.开启80端口:

vim /etc/sysconfig/iptables

#加入如下代码:-A INPUT-m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#保存退出后重启防火墙:service iptables restart


二、firewall 防火墙(Linux 7.x 及以上版本,8.x 已经和 iptables 解绑)

1.查看 firewall 服务状态:systemctl status firewalld

出现 Active:active(running)切高亮显示则表示是启动状态。

出现 Active:inactive(dead)灰色表示停止。

2.查看 firewall 的状态:firewall-cmd --state

3.开启、重启、关闭 firewalld.service 服务

# 开启:systemctl start firewalld.service

# 重启:systemctl restart firewalld.service

# 关闭:systemctl stop firewalld.service

4.查看防火墙规则:firewall-cmd --list-all

5.查询、开放、关闭端口

# 查询端口是否开放:firewall-cmd --querv-port=8080/tcp

# 开放80端口:firewall-cmd --permanent --add-port=80/tcp

# 移除端口:

firewall-cmd --permanent --remove-port=8080/tcp

#重启防火墙(修改配置后要重启防火墙):firewall-cmd --reload

# 参数解释

(1)firwall-cmd:是 Linux 提供的操作 firewall 的一个工具;

(2)--permanent:表示设置为持久;

(3)--add-port:标识添加的端口。