Linux下限制ip登陆服务器的操作记录

在日常运维工作中,为了安全考虑,常常需要对服务器登陆的ip做白名单限制。那么限制服务器登陆ip的方法主要有:
1)iptables里对ssh端口做限制
2)/etc/hosts.allow和/etc/hosts.deny限制
以上两种设置的优先级是:iptables > /etc/hosts.allow > /etc/hosts.deny

先说一下现在用的限制服务器ip登陆的限制操作:
先在/etc/sysconfig/iptables里面对ssh端口做限制,再在/etc/hosts.allow里设置允许的ip,基本/etc/hosts.deny不用动。
[[email protected] ~]# cat /etc/sysconfig/iptables
.....
-A INPUT -s 192.168.1.0/24 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -s 114.165.77.144 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -s 133.110.186.130 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

[[email protected] ~]# cat /etc/hosts.allow
#
# hosts.allow This file contains access rules which are used to
# allow or deny connections to network services that
# either use the tcp_wrappers library or that have been
# started through a tcp_wrappers-enabled xinetd.
#
# See ‘man 5 hosts_options‘ and ‘man 5 hosts_access‘
# for information on rule syntax.
# See ‘man tcpd‘ for information on tcp_wrappers
#
sshd:192.168.1.*,114.165.77.144,133.110.186.130,133.110.186.139:allow
sshd:all:deny

[[email protected] ~]# cat /etc/hosts.deny
#
# hosts.deny This file contains access rules which are used to
# deny connections to network services that either use
# the tcp_wrappers library or that have been
# started through a tcp_wrappers-enabled xinetd.
#
# The rules in this file can also be set up in
# /etc/hosts.allow with a ‘deny‘ option instead.
#
# See ‘man 5 hosts_options‘ and ‘man 5 hosts_access‘
# for information on rule syntax.
# See ‘man tcpd‘ for information on tcp_wrappers
#

------------------------------------------------------------------------------------------------------
接着对/etc/hosts.allow和/etc/hosts.deny两文件的设置做一详细介绍:

/etc/hosts.allow:用来限制服务器允许执行的ip登陆感觉比防火墙方便很多;限制特定IP来访.
思路:
1)通常的做法是利用hosts的拒绝设置,而它的设置是针对某一个具体的进程,具体的服务,在这里就是sshd了
2)设置一个网段使用的是x.x.x.0/24,比如192.168.1.0/24,这是子网匹配的方式;
如果更简单一些看起来可以直接保留前面一部分,比如131.155. ,这样可以匹配后面是任何网段,比如131.155.1.1

时间: 2024-08-27 11:07:07

Linux下限制ip登陆服务器的操作记录的相关文章

Linux下MySql的登陆和管理操作

一.mysql数据库启停1.linux下启动mysql的命令:    mysqladmin start/ect/init.d/mysql start (前面为mysql的安装路径)2.linux下重启mysql的命令:    mysqladmin restart/ect/init.d/mysql restart (前面为mysql的安装路径)3.linux下关闭mysql的命令:    mysqladmin shutdown/ect/init.d/mysql    shutdown (前面为my

linux下删除特殊字符命名文件的操作记录

在linux下,有时候会碰到以特殊字符命名的文件,要删除这些文件需要加转义符号.下面列出几个例子看看吧: [[email protected] tmp]# touch \(22\)[[email protected] tmp]# touch \1231[[email protected] tmp]# touch \\1231[[email protected] tmp]# touch \<22:23\>[[email protected] tmp]# ll-rw-r--r-- 1 root r

Linux下快速迁移海量文件的操作记录

有这么一种迁移海量文件的运维场景:比如由于现有网站服务器配置不够,需要做网站迁移(就是迁移到另一台高配置服务器上陪着),站点目录下有海量的小文件,大概100G左右,图片文件居多.目测直接拷贝过去的话,要好几天的时间.那么问题来了,这种情况下的网站数据要怎么迁移呢?另外,此网站还在运行中,白天是断然不能停止了,只能运行深夜停掉几个小时. 可以采用的方案如下:1.利用rsync进行同步.这种方法速度会慢,不过好在支持续传,在带宽不高或网站不稳定的情况下强烈建议用此方法:1)先修改一下旧站上传图片的功

Linux下静态IP地址的设置及TFTP服务的搭建

TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂.开销不大的文件传输服务.TFTP承载在UDP上,提供不可靠的数据流传输服务,不提供存取授权与认证机制,使用超时重传方式来保证数据的到达. 一.在谈TFTP之前,先简单讲一下Linux网络配置,网络中最重要的当然是IP地址了,这里不讲IP协议,在后面的网络编程再讲解,这里主要学习一下Linux下配置IP,配置IP地址的方法

linux下查找进程及终止进程操作的相关命令

使用linux操作系统,难免遇到一些软件"卡壳"的问题,这时就需要使用linux下强大的kill命令来结束相关进程.这在linux系统下是极其容易的事情,你只需要kill xxx即可,这里xxx代表与此软件运行相关的进程PID号.首先,我们需要使用linux下另外一个命令ps查找与进程相关的PID号:ps aux | grep program_filter_word1)ps a 显示现行终端机下的所有程序,包括其他用户的程序.2)ps -A 显示所有程序.3)ps c 列出程序时,显示

CentOS/Linux下设置IP地址

CentOS/Linux下设置IP地址 1:临时修改:1.1:修改IP地址# ifconfig eth0 192.168.100.100 1.2:修改网关地址# route add default gw 192.168.100.1 dev eth0 1.3:修改DNS# echo "nameserver 8.8.8.8" >> /etc/resolv.conf 这个时候就可以上网了,上网的IP地址为192.168.100.100,网关地址为192.168.100.1.但是这

Linux下安装配置Apache服务器

Linux下安装配置Apache服务器 1. 安装Apache [[email protected] ~]# yum –y install httpd 2. 启动Apache [[email protected] ~]# systemctl start httpd 3. 查看进程 [[email protected] ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib

linux下搭建HTTP网站服务器和网站日志分析工具AWStats的使用

服务器IP地址:192.168.4.5 服务器主机名:srv5.tarena.com 1.在服务器端安装httpd软件包 [[email protected] /]# yum -y install httpd [[email protected] /]# service httpd start [[email protected] /]# chkconfig httpd on 2.在客户机端验证 在浏览器中输入192.168.4.5 如果显示欢迎页面表示服务器搭建成功 3.部署网页文档 首先将欢

linux下自动ftp到服务器对比拷贝指定目录下文件

#!/bin/bash process=8 PWD=`pwd` DAT=`date` ftpip="192.168.1.1" user="ftp_username" password="ftp_password" local_dir="/home/" getlist() { ftp -n $ftpip <<EOF |awk '{print $9}'|sed '/^$/d' >$PWD/list user $u