SLES 15 SP4 企业级部署:静态IP、防火墙与sudo用户授权3步配置
SLES 15 SP4 企业级部署静态IP、防火墙与sudo用户授权3步配置在企业生产环境中部署SUSE Linux Enterprise ServerSLES15 SP4时系统安装完成后的初始化配置是确保服务器安全稳定运行的关键环节。本文将聚焦三个核心配置任务静态IP地址设置、防火墙规则配置以及sudo用户权限管理为DevOps工程师和系统管理员提供一套可复用的标准化流程。1. 网络配置静态IP与DNS设置企业级服务器必须使用静态IP地址以确保服务可达性。SLES 15 SP4提供两种主流配置工具1.1 YaST图形化配置推荐用于桌面环境sudo yast2 network在YaST界面中选择有线连接选项卡点击编辑按钮进入详细配置切换至静态地址模式并填写IP地址如192.168.1.100子网掩码255.255.255.0默认网关192.168.1.1在主机名/DNS选项卡配置主DNS服务器8.8.8.8备用DNS服务器8.8.4.4搜索域名example.com提示配置完成后需点击确定保存YaST会自动重启网络服务使配置生效。1.2 nmtui命令行配置适用于无图形界面环境sudo nmtui操作流程选择Edit a connection选择要配置的网卡通常为eth0或ens192将IPv4配置改为Manual填写IP地址、网关和DNS信息按Tab键选择OK保存验证配置是否生效ip addr show eth0 ping -c 4 google.com关键配置文件位置/etc/sysconfig/network/ifcfg-eth0/etc/resolv.conf2. 防火墙配置基础服务放行SLES 15 SP4默认使用firewalld作为防火墙解决方案。以下是企业环境推荐的最小化安全配置2.1 放行基础服务端口sudo firewall-cmd --permanent --add-servicessh sudo firewall-cmd --permanent --add-servicehttp sudo firewall-cmd --permanent --add-servicehttps sudo firewall-cmd --reload2.2 验证防火墙规则sudo firewall-cmd --list-all预期输出应包含services: ssh http https ports: protocols: masquerade: no2.3 高级安全配置可选对于需要更严格安全策略的环境# 限制SSH访问源IP sudo firewall-cmd --permanent --add-rich-rulerule familyipv4 source address192.168.1.0/24 service namessh accept # 设置默认区域为dmz sudo firewall-cmd --set-default-zonedmz防火墙状态管理命令启动sudo systemctl start firewalld开机自启sudo systemctl enable firewalld状态检查sudo firewall-cmd --state3. 用户权限管理sudo配置最佳实践直接使用root账户存在严重安全风险应遵循最小权限原则配置sudo访问。3.1 创建管理用户sudo useradd -m -G wheel adminuser sudo passwd adminuser3.2 配置sudo权限编辑sudoers文件sudo visudo推荐配置# 取消wheel组的注释 %wheel ALL(ALL) ALL # 添加特定命令权限更安全 adminuser ALL(ALL) /usr/bin/zypper, /usr/bin/systemctl3.3 安全增强措施# 设置密码策略 sudo chage -M 90 -m 7 -W 14 adminuser # 禁用root SSH登录 sudo sed -i s/^PermitRootLogin yes/PermitRootLogin no/ /etc/ssh/sshd_config sudo systemctl restart sshd用户权限验证方法sudo -l -U adminuser4. 配置持久化与故障排查4.1 网络配置备份与恢复# 备份配置 sudo tar -czf /backup/network_config_$(date %F).tar.gz /etc/sysconfig/network/ # 恢复配置 sudo tar -xzf /backup/network_config_2023-08-20.tar.gz -C /4.2 常见问题排查网络连接故障journalctl -u NetworkManager --no-pager -n 50 ip route show防火墙规则冲突sudo firewall-cmd --check-config sudo iptables -L -n -vsudo权限问题sudo tail -n 20 /var/log/auth.log getent group wheel5. 自动化配置方案对于需要批量部署的场景可考虑以下自动化方案5.1 使用Ansible Playbook--- - hosts: servers become: yes tasks: - name: Configure static IP template: src: ifcfg-eth0.j2 dest: /etc/sysconfig/network/ifcfg-eth0 notify: restart network - name: Configure firewall firewalld: service: {{ item }} permanent: yes state: enabled loop: - ssh - http - https - name: Create admin user user: name: adminuser groups: wheel password: {{ password | password_hash(sha512) }} - name: Secure SSH config lineinfile: path: /etc/ssh/sshd_config regexp: ^{{ item.regexp }} line: {{ item.line }} loop: - { regexp: PermitRootLogin, line: PermitRootLogin no } - { regexp: PasswordAuthentication, line: PasswordAuthentication no } notify: restart sshd5.2 使用SaltStack状态文件network_config: file.managed: - name: /etc/sysconfig/network/ifcfg-eth0 - source: salt://network/files/ifcfg-eth0 - template: jinja firewall_rules: firewalld.present: - name: public - services: - ssh - http - https user_setup: user.present: - name: adminuser - groups: - wheel - password: $6$rounds656000$salt$hashedpassword实际部署中建议结合企业现有的配置管理工具制定标准化部署流程确保所有服务器配置一致且符合安全规范。对于关键业务系统应在变更窗口进行操作并做好完整的回滚预案。