关于linux:linux-强行踢出对应的用户并禁止ip登录

  1. 踢出指定的用户
who  #查看所用的连贯
who -m # 查看以后的用户
pkill -kill -t 对应的pts/$id
  1. 限度ip拜访的两种形式

应用hosts.allow和hosts.deny来设置ip白名单和黑名单,/etc/目录下.

先级为先查看hosts.deny,再查看hosts.allow,   
后者设定可越过前者限度,   
例如:   
1.限度所有的ssh,   
除非从216.64.87.0 - 127上来。   
hosts.deny:   
in.sshd:ALL   
hosts.allow:   
in.sshd:216.64.87.0/255.255.255.128  
   
2.封掉216.64.87.0 - 127的telnet   
hosts.deny   
in.sshd:216.64.87.0/255.255.255.128  
   
3.限度所有人的TCP连贯,除非从216.64.87.0 - 127拜访   
hosts.deny   
ALL:ALL   
hosts.allow   
ALL:216.64.87.0/255.255.255.128  
   
4.限度216.64.87.0 - 127对所有服务的拜访   
hosts.deny   
ALL:216.64.87.0/255.255.255.128  
   
其中冒号后面是TCP daemon的服务过程名称,通常零碎   
过程在/etc/inetd.conf中指定,比方in.ftpd,in.telnetd,in.sshd   
   
其中IP地址范畴的写法有若干中,次要的三种是:   
1.网络地址--子网掩码形式:   
216.64.87.0/255.255.255.0  
2.网络地址形式(我本人这样叫,呵呵)   
216.64.(即以216.64打头的IP地址)   
3.缩略子网掩码形式,既首屈一指进制子网掩码后面有多少个“1”比方:   
216.64.87.0/255.255.255.0 -- 216.64.87.0/24  
   
设置好后,要重新启动  
# /etc/rc.d/init.d/xinetd restart  
# /etc/rc.d/init.d/network restart

应用iptables命令.

单个IP的命令是  
iptables -I INPUT -s 81.241.219.171 -j DROP  
   
封IP段的命令是  
iptables -I INPUT -s 97.47.225.0/16 -j DROP  
iptables -I INPUT -s 97.47.225.0/16 -j DROP  
iptables -I INPUT -s 97.47.225.0/16 -j DROP  
   
封整个段的命令是  
iptables -I INPUT -s 97.47.225.0/8 -j DROP  
   
封几个段的命令是  
iptables -I INPUT -s 97.47.225.0/24 -j DROP  
iptables -I INPUT -s 97.47.225.0/24 -j DROP   
   
   
服务器启动自运行  
有三个办法:  
1、把它加到/etc/rc.local中  
2、vi /etc/sysconfig/iptables能够把你以后的iptables规定放到/etc/sysconfig/iptables中,系统启动iptables时主动执行。  
3、service   iptables   save 也能够把你以后的iptables规定放/etc/sysconfig/iptables中,系统启动iptables时主动执行。  
后两种更好些,个别iptables服务会在network服务之前启来,更平安  
   
解封:  
iptables -L INPUT  
iptables -L --line-numbers 而后iptables -D INPUT 序号   
   
   
iptables 限度ip拜访  
通过iptables限度9889端口的拜访(只容许192.168.1.100、192.168.1.101、192.168.1.102),其余ip都禁止拜访  
iptables -I INPUT -p tcp --dport 9889 -j DROP  
iptables -I INPUT -s 192.168.1.100 -p tcp --dport 9889 -j ACCEPT  
iptables -I INPUT -s 192.168.1.101 -p tcp --dport 9889 -j ACCEPT  
iptables -I INPUT -s 192.168.1.102 -p tcp --dport 9889 -j ACCEPT

优先级为先查看hosts.deny,再查看hosts.allow,   
    后者设定可越过前者限度,   
    例如:   
    1.限度所有的ssh,   
    除非从216.64.87.0 - 127上来。   
    hosts.deny:   
    in.sshd:ALL   
    hosts.allow:   
    in.sshd:216.64.87.0/255.255.255.128  
       
    2.封掉216.64.87.0 - 127的telnet   
    hosts.deny   
    in.sshd:216.64.87.0/255.255.255.128  
       
    3.限度所有人的TCP连贯,除非从216.64.87.0 - 127拜访   
    hosts.deny   
    ALL:ALL   
    hosts.allow   
    ALL:216.64.87.0/255.255.255.128  
       
    4.限度216.64.87.0 - 127对所有服务的拜访   
    hosts.deny   
    ALL:216.64.87.0/255.255.255.128  
       
    其中冒号后面是TCP daemon的服务过程名称,通常零碎   
    过程在/etc/inetd.conf中指定,比方in.ftpd,in.telnetd,in.sshd   
       
    其中IP地址范畴的写法有若干中,次要的三种是:   
    1.网络地址--子网掩码形式:   
    216.64.87.0/255.255.255.0  
    2.网络地址形式(我本人这样叫,呵呵)   
    216.64.(即以216.64打头的IP地址)   
    3.缩略子网掩码形式,既首屈一指进制子网掩码后面有多少个“1”比方:   
    216.64.87.0/255.255.255.0 -- 216.64.87.0/24  
       
    设置好后,要重新启动  
    # /etc/rc.d/init.d/xinetd restart  
    # /etc/rc.d/init.d/network restart

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理