技术支持

为您提供7*24小时在线技术支持、安全技术专家、行业资深安全顾问服务。400-888-1688

系统安全相关

您当前位置首页 > 技术支持 > 系统安全相关

FreeBSD 12.1系统安全配置与防火墙管理

FreeBSD以其稳定性和安全性著称,广泛用于网络服务器。本文介绍FreeBSD 12.1系统的安全配置和防火墙管理。

一、系统更新

code
code
code
freebsd-update fetch
freebsd-update install
portsnap fetch update
pkg update && pkg upgrade -y

二、PF防火墙配置

code
code
code
# /etc/pf.conf 配置示例
ext_if = "em0"
block in all
pass out all keep state
set skip on lo0
pass in on $ext_if proto tcp to ($ext_if) port 2222 keep state
pass in on $ext_if proto tcp to ($ext_if) port 80,443 keep state

# 启动PF
echo 'pf_enable="YES"' >> /etc/rc.conf
service pf start

三、安全加固配置

code
code
code
# /etc/sysctl.conf
net.inet.icmp.drop_redirect=1
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.inet.tcp.syncookies=1

# 用户管理
pw useradd admin -m -G wheel -s /usr/local/bin/bash
passwd admin
pkg install -y sudo
echo 'admin ALL=(ALL) ALL' >> /usr/local/etc/sudoers

四、SSH限制

code
code
code
echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
service sshd restart

五、文件系统安全

code
code
code
# 文件系统权限掩码
echo 'umask 027' >> /etc/profile

# 重要文件加不可变标志
chflags schg /etc/rc.conf
chflags schg /etc/pf.conf
chflags schg /etc/ssh/sshd_config
# 查看文件标志
ls -lo /etc/rc.conf

# 移除不可变标志
chflags noschg /etc/rc.conf

# 配置自动挂载选项
cat >> /etc/fstab << 'EOF'
/dev/da0p2 / ufs rw,noatime,acls 1 1
/dev/da0p3 /var ufs rw,noatime,noexec,nosuid 1 1
/dev/da0p4 /tmp ufs rw,noatime,noexec,nosuid 1 1
/dev/da0p5 /home ufs rw,noatime,nosuid 1 1
EOF

六、网络服务安全

code
code
code
# 限制inetd服务
# 查看 /etc/inetd.conf,注释不需要的服务

# 禁用不必要的服务
cat >> /etc/rc.conf << 'EOF'
sendmail_enable="NONE"
linux_enable="NO"
nfs_server_enable="NO"
sshd_enable="YES"
ntpd_enable="YES"
EOF

# TCP Wrappers配置(如使用)
cat >> /etc/hosts.allow << 'EOF'
sshd: 192.168.0.0/16 : allow
sshd: ALL : deny
EOF

七、Ports安全管理

code
code
code
# 定期更新ports
portsnap fetch update

# 使用pkg管理包
pkg update
pkg upgrade

# 检查已知漏洞
pkg audit -F

# 查看已安装包
pkg info

# 删除未使用的依赖
pkg autoremove
这条帮助是否解决了您的问题? 已解决 未解决

安全合格的云服务,让您的业务轻松上云!

立即选购
https://affim.baidu.com/unique_50626027/chat?siteId=21806899&userId=50626027&siteToken=f4b13c0dda3b403b51fd8811d5a360c7