debian

Debian ifconfig安全设置指南

小樊
46
2025-08-21 04:13:00
栏目: 智能运维

Debian ifconfig安全设置指南

一、优先使用ip命令替代

ifconfig已逐步被弃用,建议使用功能更强大的ip命令,例如:

二、限制ifconfig命令使用权限

  1. 删除或禁用ifconfig
    • 卸载net-tools包(含ifconfig):
      sudo apt remove --purge net-tools
    • 禁止普通用户执行:编辑/etc/sudoers,添加:
      Defaults:username !/sbin/ifconfig(替换为实际用户名)

三、安全配置网络接口

  1. 静态IP配置(持久化)
    编辑/etc/network/interfaces(Debian 9及之前):

    auto eth0  
    iface eth0 inet static  
        address 192.168.1.100  
        netmask 255.255.255.0  
        gateway 192.168.1.1  
    

    重启网络:sudo systemctl restart networking

  2. 动态IP配置(DHCP)
    编辑/etc/network/interfaces

    auto eth0  
    iface eth0 inet dhcp  
    

    重启网络生效

四、增强系统安全

  1. 防火墙配置
    使用ufw限制接口访问:

    sudo apt install ufw  
    sudo ufw deny in on eth0 from 192.168.1.0/24  # 拒绝指定IP段  
    sudo ufw allow ssh  # 允许SSH  
    sudo ufw enable  
    
  2. SSH安全加固

    • 禁用root远程登录:编辑/etc/ssh/sshd_config,设置PermitRootLogin prohibit-password
    • 启用密钥认证:将公钥添加至~/.ssh/authorized_keys,并设置PasswordAuthentication no

五、其他注意事项

参考来源

0
看了该问题的人还看了