图文结合讲解linux实现简易校园防火墙(文字原理+代码)

简易类VPN

  • 简单原理讲解
    • 简单版本
    • 详细版本
    • 具体代码
    • web端
      • dao
      • servlet
      • util
      • html
  • Java单类
  • Shell脚本
    • start.sh
    • loadConfiguration.sh
    • InitAllowedIp.sh
    • splitIp.sh
    • lastIptable.sh
    • InitAllowedIp.txt
    • InitIptable.txt
    • lastIptable.txt
    • version.txt

简单原理讲解

防火墙使用Linux自带的iptable防火墙
大部分校园内部分两种登录

  1. 通过VPN登录
  2. 通过登录网页登录
    由于应用层协议都是基于传输层协议的既TCP协议和UDP协议,TCP协议是可靠传输,在发送的时候都会携带这发送方的IP和MAC地址。由于HTTP协议是基于TCP协议的所以在访问的时候也会携带IP和MAC地址。
    当登录成功之后,会告诉防火墙将登录成功的IP设置为允许,外网数据就被设置为放行,可以访问内部网络了
    IP登录之后,第二次登录会判断和上次ip是否一致不一致替换

简单版本

图文结合讲解linux实现简易校园防火墙(文字原理+代码)_第1张图片因为是多账户登录,每次登录都会更改配置文件同时对配置文件的标记文件也进行修改,造成了标志文件每次登录都会覆盖标志文件的问题。被反复覆盖
Shell文件需要记录上次标志文件的版本号,如果版本号发生改变的话,重启配置文件—既标记返回覆盖也无关系
修改配置文件的时候如果同时修改配置文件的话会产生干扰,退出修改,登录新增。产生覆盖问题
方法:配置文件可以分成多份 既防火墙文件 将配置规则放入d、b、c配置文件,但是将d、b、c的文件的引入方式放入a中这样我们只需要调用a文件就能同时引入d、b、c文件。重启的时候只要重启a文件就可以
然后通过指令解析解析配置文件就行

详细版本

图文结合讲解linux实现简易校园防火墙(文字原理+代码)_第2张图片登录之后防火墙允许那些ip登录是需要记录到数据库中,通过管理平台进行管理—(指定那些ip需要登录,那些ip不可以登录)
大概流程:多个用户先进行登录,用户的账户密码来源—管理平台导入进来—,登录完毕b网站之后,修改配置文件,并且修改数据库同意登录用户的ip访问A网站
既修改完配置文件之后还要修改数据库
登录完之后–新增ip和删除ip需要在在表中做记录。假设数据库中有《用户表》《用户和ip对应表》《新增ip表》《删除ip表》《最新时间表》每次登录都需要对用户和ip对应表进行更新。登录之后发现是新增的ip那么需要删除以前对应的ip。删除IP需要记录删除的时间。写一个打成jar包的java文件(定时器)每隔一段时候都会读取最新删除的ip将其以字符串方式存储到配置文件中。例如aaa文件。《最新时间表》记录最新删除ip的时间。例如bbb文件为新增ip文件和aaa文件一样
定时器定时调用脚本,脚本读取aaa文件或者bbb文件,获取最新删除(新增)ip拼接防火墙删除ip的指令----shell脚本读取aaa文件内容根,设定变量字符串分割,循环、字符串拼接、拼接好指令之后,执行指令(指令执行的关键字)
导出含有主方法jar包,由定时器执行,测试是否可以定时向数据集插入数据,java修改配置文件内存

具体代码

web端

dao

package yaojing.dao;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {

	public static void main(String[] args) {

	}

	private static String driver = "com.mysql.jdbc.Driver";//驱动
	private static String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false";
	private static String user = "root";
	private static String password = "2020";

	public Connection conn;

	public DBConnection() {

		try {
			// 加载驱动jar包
			Class.forName(driver);   // 反射:获取类的信息
			conn = (Connection) DriverManager.getConnection(url, user, password);

			// if(!conn.isClosed())
			// System.out.println("Succeeded connecting to the Database!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void close() {
		try {
			this.conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
package yaojing.dao;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MysqlUtil {


	/**
	 *  添加
	 * @param sql insert
	 * @return
	 */
	public static int add(String sql) {
		System.out.println("sql="+sql);
        int i=0;
        
        DBConnection db = new DBConnection();
        try {        
            PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(sql);
            preStmt.executeUpdate();
            preStmt.close();
            db.close();
            i = 1;
       
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
	}
	
	/**
	 *查询
	 * @param sql
	 * @param colums
	 * @return
	 */
    public static ArrayList showUtil(String sql, String[] colums){
        
    	 ArrayList  result = new  ArrayList();
         DBConnection db = new DBConnection();
         try {
            Statement stmt = (Statement) db.conn.createStatement();
            ResultSet rs = (ResultSet) stmt.executeQuery(sql);

            while(rs.next()){
               String[] dataRow = new String[colums.length];
               for( int i = 0; i < dataRow.length; i++ ) {
            	   dataRow[i] = rs.getString( colums[i] );
               }
               result.add(dataRow);
            }
            rs.close();
            db.close();//
        } catch (SQLException e) {
            e.printStackTrace();
        } 
         
         return result;
    }

    
    /**
     * 获取表中数据的数量
     * @param sql
     * @return
     */
    
    public static int getCount(String sql) {
		int sum = 0;
		DBConnection db = new DBConnection();
		try {
			Statement stmt = (Statement) db.conn.createStatement();
            ResultSet rs = (ResultSet) stmt.executeQuery(sql);
            while (rs.next()) {
            	sum += rs.getInt(1);
            	}
            rs.close();
            db.close();
		} catch (Exception e) {
		}
		return sum;
	}
    
    /**
     *  通过Sql语句查询并且将值转为JSON
     * @param sql
     * @param colums
     * @return
     */
    public static String getJsonBySql( String sql, String[] colums){
        
     System.err.println("sql:" + sql);
   	 ArrayList  result = new  ArrayList();
        DBConnection db = new DBConnection();
        try {
           Statement stmt = (Statement) db.conn.createStatement();
           ResultSet rs = (ResultSet) stmt.executeQuery(sql);
           while(rs.next()){
              String[] dataRow = new String[colums.length];
              for( int i = 0; i < dataRow.length; i++ ) {
           	   dataRow[i] = rs.getString( colums[i] );
              }
              result.add(dataRow);
           }
           rs.close();
           db.close();//
       } catch (SQLException e) {
           e.printStackTrace();
       } 
        
        return listToJson(result,colums);
   }

    /**
     * 更新
     * @param sql
     * @return
     */
    public static int update(String sql) {
        int i =0;
        DBConnection db = new DBConnection();
        try {
            PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(sql);
            preStmt.executeUpdate();
            preStmt.close();
            db.close();
            i = 1;
            System.out.println("sql" + sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }
    

    /**
     *  json
     * @param sql select * from 表
     * @param params [id,name,sex,age] 
     * @return
     */
    public static String show(String sql, String[] params){
    	
    	List< Map > listmap = new ArrayList();
    	
         DBConnection db = new DBConnection();
         ResultSet rs = null;
         try {
            Statement stmt = (Statement) db.conn.createStatement();
            rs = (ResultSet) stmt.executeQuery(sql);
            while(rs.next()){
            	Map map = new HashMap();
            	for(int i = 0; i < params.length; i++) {
            		map.put(params[i], rs.getString(params[i]));
            	}
            	listmap.add(map);
            }
            rs.close();
            db.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
       
		return mapToJson(listmap); 
         
    }
    
  
    
  /**
   * 删除
   * @param delstr
   * @return
   */
    public static int del(String delstr) {
        int i=0;
        DBConnection db = new DBConnection();
        try {    
            PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(delstr);
            preStmt.executeUpdate();
            
            preStmt.close();
            db.close();
            i = 1;
            System.out.println("sql" + delstr);
        } catch (SQLException e){
            e.printStackTrace();
        }
        return i;
    }

    
    /**
     * map转JSON
     * @param maplist
     * @return
     */
    public static String mapToJson( List> maplist ) {
    	String jsonData = "{ \"data\":[";
		for(int i = 0; i < maplist.size(); i++) {
			String outstr = "[\"" ;
			int size = 0;
			for(String value : maplist.get(i).values()){
				size += 1;
				outstr += value;
				if( size < maplist.get(i).values().size() ) {
				     outstr += "\",\"";
				}
			}
		    outstr += "\"]";
		    
		    if(i < maplist.size() -1) {
		    	outstr += ",";
		    }
			jsonData += outstr;
			
		}
		jsonData += "]}";
		
		return jsonData;
    }
    
    
    
    public static String listToJsonLayui( ArrayList list,String[] colums) {

    	String jsonStr = "[{\"status\":0}, {\"message\": \"鎴愬姛\" },{\"count\": 1000},{\"rows\":{\"item\":[";
    			for(int i = 0; i < list.size(); i++) {
    				String arr = "{";
    				for( int j = 0; j < list.get(0).length; j++) {
    					
    					if( list.get(i)[j] == null || "NULL".equals(list.get(i)[j])) {
    						arr += "\"\"";
    					}else {
    						arr += "\"" + colums[j] + "\""+":" ;
    						arr +=  "\"" + list.get(i)[j].replace("\"","\\\"") + "\"";
    					}
    					
    					if( j < list.get(0).length - 1 ) {
    						arr += ",";
    					}
    				}
    				arr += "}";
    				if( i < list.size() - 1 ) {
						arr += ",";
					}
    				
    				jsonStr += arr;
    			}
    			jsonStr += "]}}]";
    	
    	return jsonStr;
    }
    

    public static String listToJson( ArrayList list,String[] colums) {

    	String jsonStr = "{ \"data\":[";
    			for(int i = 0; i < list.size(); i++) {
    				String arr = "{";
    				for( int j = 0; j < list.get(0).length; j++) {
    					
    					if( list.get(i)[j] == null || "NULL".equals(list.get(i)[j])) {
    						arr += "\"\"";
    					}else {
    						arr += "\"" + colums[j] + "\""+":" ;
    						arr +=  "\"" + list.get(i)[j].replace("\"","\\\"") + "\"";
    					}
    					
    					if( j < list.get(0).length - 1 ) {
    						arr += ",";
    					}
    				}
    				arr += "}";
    				if( i < list.size() - 1 ) {
						arr += ",";
					}
    				
    				jsonStr += arr;
    			}
    			jsonStr += "]}";
    	
    	return jsonStr;
    }
    public static  void listToModel(List list, T t) throws Exception {
        Field[] fields = t.getClass().getDeclaredFields();
        if (list.size() != fields.length) {
            return;
        }
        for (int k = 0, len = fields.length; k < len; k++) {
            // 根据属性名称,找寻合适的set方法
            String fieldName = fields[k].getName();
            String setMethodName = "set" + fieldName.substring(0, 1).toUpperCase()
                    + fieldName.substring(1);
            Method method = null;
            Class clazz = t.getClass();
            try {
                method = clazz.getMethod(setMethodName, new Class[] { list.get(k).getClass() });
                System.out.println("list.get("+k+").getClass():"+list.get(k).getClass());
            } catch (SecurityException e1) {
                e1.printStackTrace();
                return;
            } catch (NoSuchMethodException e1) {
                String newMethodName = "set" + fieldName.substring(0, 1).toLowerCase()
                        + fieldName.substring(1);
                try {
                    method = clazz.getMethod(newMethodName, new Class[] { list.get(k).getClass() });
                } catch (SecurityException e) {
                    e.printStackTrace();
                    return;
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                    return;
                }
            }
            if (method == null) {
                return;
            }
            method.invoke(t, new Object[] { list.get(k) });
        }
    }

}
 
  

servlet

package yaojing.servlet;


import yaojing.dao.MysqlUtil;
import yaojing.util.IpUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

@WebServlet(name = "UserServlet", value = "/UserServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        //获取账户
        String account = request.getParameter("account");//获取用户
        //获取密码
        String password = request.getParameter("password");
        System.out.println("账户 "+account + " 密码 " +password);
        String json;

        if(account==null || account.equals("")||password==null||password.equals("")){
            json = "{\"code\":\"200\",\"message\":\"账户或者密码为空\"}";
            response.getWriter().append(json);
            return;
        }
        String sql =  "select * from user where account = '"+account+"' and password = '"+password+"';";
        String[] colums = {"id","account","password"};
        ArrayList arrayList = MysqlUtil.showUtil(sql, colums);
        System.out.println(arrayList.toArray());
        if (arrayList.size() == 0) {
            json = "{\"code\":\"200\",\"message\":\"查无此人\"}";
        }else {

            //获取真实ip
            String ip = IpUtil.getIpAddress(request);
            json = "{\"code\":\"200\",\"message\":\"登录成功\",\"ip\":\""+ip+"\"}";
            //判断有没有绑定其他ip 如果绑定了替换 并且将删除的ip保存起来
//            TODO 不像写直接替换掉每次每次重新暴力拉去
            //先查找对应表里有没有存储对应关系
            //拿到登录人的id
            String id = arrayList.get(0)[0];
            String showIpSql = "select userid from userip  where userid  = "+id+" ";
            String[] showIpcolums = {"id","userid","ip","logtim"};
            ArrayList showIpList = MysqlUtil.showUtil(sql, colums);
            //判断有没有登录过
            if(showIpList.size()!=0){ //有  修改
                System.out.println("有对应的user " +"修改器对应的ip为" + id);
                String showIpId = showIpList.get(0)[0];
                String updateIpIdSql = "update userip set userip.ip ='"+ip+"' where userid = "+showIpId+"";
                MysqlUtil.update(updateIpIdSql);
            }else{ //没有添加
                String insertUserip = "insert into userip(userid,ip,logtim) values("+id+",'"+ip+"','"+new Date()+"')";
                MysqlUtil.add(insertUserip);
            }
            String UUID = java.util.UUID.randomUUID().toString();
            String insertVersion = "update version set version='"+UUID+"' where id = '1'";
            MysqlUtil.add(insertVersion);
            request.getSession().setAttribute("user",id);//登录成功标记
        }
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}

package yaojing.servlet;



import yaojing.dao.MysqlUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ExitServlet", value = "/ExitServlet")
public class ExitServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        String id = (String)request.getSession().getAttribute("user");
        //直接删除对应的ip
        String updateIpIdSql = "update userip set userip.ip ='' where userid = "+id+"";
        MysqlUtil.update(updateIpIdSql);
        //更新版本号
        String UUID = java.util.UUID.randomUUID().toString();
        String insertVersion =  "update version set version='"+UUID+"' where id = '1'";
        MysqlUtil.add(insertVersion);
        String json = "{\"code\":\"200\",\"message\":\"退出成功\"}";
        response.getWriter().append(json);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}


util

package yaojing.util;



import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取用户访问ip地址
 */
public class IpUtil {
    public static String getIpAddress(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        // 获取到多个ip时取第一个作为客户端真实ip
        if (StringUtils.isNotEmpty(ip) && ip.contains(",")) {
            String[] ipArray = ip.split(",");
            if (ArrayUtils.isNotEmpty(ipArray)) {
                ip = ipArray[0];
            }
        }
        return ip;
    }
}


html




    
    Insert title here
    


用户名: 
密码:



    
    Title
    



    



Java单类

import db.DBConnection;
import db.MysqlUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main{
    //从数据库查询所有ip
    public static void main(String[] args) {
        char index = args[0].charAt(0);
        switch (index){
            case '1':
                System.out.println(ShowuseVersion());
                break;
            case '2':
                System.out.println(ShowuserIp());
                break;
            default:
                System.out.println("什么都没有啊");
                break;
        }
    }
    public static String ShowuseVersion(){
        String sql= "select * from version";
        String[] coml = new String[]{"id","version"};
        List> insertIp = show(sql, coml);
        List version = new ArrayList();
        for (Map userip : insertIp) {
            version.add(userip.get("version"));
        }
        return version.get(version.size()-1);
    }
    public static String ShowuserIp(){
        String myip ="";
        String sql= "select * from userip";
        String[] coml = new String[]{"id","userid","ip"};
        List> insertIp = show(sql, coml);
        List ip = new ArrayList();
        for (Map userip : insertIp) {
            ip.add(userip.get("ip"));
        }
        for (int i = 0; i < ip.size(); i++) {
            myip+=ip.get(i);
            if(i != ip.size() - 1){
                myip+=",";
            }
        }
        return myip;
    }
    public static List> show(String sql, String[] params){

        List> listmap = new ArrayList();

        DBConnection db = new DBConnection();
        ResultSet rs = null;
        try {
            Statement stmt = (Statement) db.conn.createStatement();
            rs = (ResultSet) stmt.executeQuery(sql);
            while(rs.next()){
                Map map = new HashMap();
                for(int i = 0; i < params.length; i++) {
                    map.put(params[i], rs.getString(params[i]));
                }
                listmap.add(map);
            }
            rs.close();
            db.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return listmap;

    }
}


    4.0.0
    
    com.yaojing
    VpnTest
    1.0-SNAPSHOT

    
    jar

    
    
        
        1.8
        
        1.8
        
        UTF-8
        
        UTF-8
        
        UTF-8

    

    
        
        
            mysql
            mysql-connector-java
            5.1.6
        
    
  
      
      VpnTest

      
            
            
                org.apache.maven.plugins
                maven-surefire-plugin 
                
                true
                
            
          

          
          
              org.apache.maven.plugins
              maven-assembly-plugin
              3.0.0
              
                  
                      
                          Main
                      
                  
                  
                      jar-with-dependencies
                  
              
              
                  
                      make-assembly 
                      package 
                      
                          single
                      
                  
              
          
      
  

Shell脚本

我是练习Shell脚本是如何使用的,所以用的Shell实现,但是我不是很推荐使用Shell,现在服务器都自带py推荐使用py
以下Shell脚本按照执行顺序粘贴
只需要定时器crontab定时执行start.sh就可以

start.sh

ver=$(cat version.txt)
java -Dfile.encoding=utf-8 -jar VpnTest.jar 1 >version.txt
ver2=$(cat version.txt)
if [ $ver -eq $ver2 ]
then
  echo 'yes'
else
  sh ./loadConfiguration.sh
fi

loadConfiguration.sh

#!/bin/bash
#获取ip
sh InitAllowedIp.sh
#分割ip文件
sh splitIp.sh $(cat InitAllowedIp.txt) "InitAllowedIp.txt"
#拿到基础设置
cp InitIptable.txt lastIptable.sh

for line in $(cat InitAllowedIp.txt)
do

ipt='iptables -A INPUT -s '${line}' -p tcp --dport 8080 -j ACCEPT';
echo $ipt >> lastIptable.sh ;
done
#保存在配置文件里
iptables -F
service iptables save
echo 'iptables -P INPUT DROP' >> lastIptable.sh
echo 'service iptables save' >> lastIptable.sh
echo 'service iptables restart' >> lastIptable.sh
sh lastIptable.sh

InitAllowedIp.sh

#!/bin/bash
java -jar ./VpnTest.jar 2 >InitAllowedIp.txt

splitIp.sh

#!/bin/bash
ip=${1};
url=${2};
#清空指定文件
sed -i '1,$d' $url
fun_Host_Isolcpus(){
    param=$1
    flag=$(echo $param | grep ",")
    if [ $flag ]; then
        #有逗号,看有几个逗号
        fun_Host_Isolcpus_do ${param%%,*}
        fun_Host_Isolcpus ${param#*,}
    else
        #没有逗号,一次就OK
        fun_Host_Isolcpus_do $param
    fi
}
fun_Host_Isolcpus_do(){
	echo $1>>$url;
    echo $1;
}
fun_Host_Isolcpus $ip

lastIptable.sh

ptables -A INPUT -i lo -j ACCEPT;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT;
iptables -A OUTPUT -j ACCEPT;
iptables -A INPUT -p tcp --dport 22 -j ACCEPT;
iptables -A INPUT -p tcp --dport 80 -j ACCEPT;
iptables -A INPUT -p tcp --dport 443 -j ACCEPT;
iptables -A INPUT -p tcp --dport 21 -j ACCEPT;
iptables -A INPUT -p tcp --dport 20 -j ACCEPT;
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT;
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT;
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 9999 -j ACCEPT
iptables -A INPUT -s 128.0.0.1 -p tcp --dport 9999 -j ACCEPT
service iptables save
service iptables restart

InitAllowedIp.txt

127.0.0.1
128.0.0.1

InitIptable.txt

ptables -A INPUT -i lo -j ACCEPT;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT;
iptables -A OUTPUT -j ACCEPT;
iptables -A INPUT -p tcp --dport 22 -j ACCEPT;
iptables -A INPUT -p tcp --dport 80 -j ACCEPT;
iptables -A INPUT -p tcp --dport 443 -j ACCEPT;
iptables -A INPUT -p tcp --dport 21 -j ACCEPT;
iptables -A INPUT -p tcp --dport 20 -j ACCEPT;
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT;
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT;

lastIptable.txt

ptables -A INPUT -i lo -j ACCEPT;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT;
iptables -A OUTPUT -j ACCEPT;
iptables -A INPUT -p tcp --dport 22 -j ACCEPT;
iptables -A INPUT -p tcp --dport 80 -j ACCEPT;
iptables -A INPUT -p tcp --dport 443 -j ACCEPT;
iptables -A INPUT -p tcp --dport 21 -j ACCEPT;
iptables -A INPUT -p tcp --dport 20 -j ACCEPT;
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT;
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT;
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 9999 -j ACCEPT
iptables -A INPUT -s 128.0.0.1 -p tcp --dport 9999 -j ACCEPT

version.txt

444

你可能感兴趣的:(linux,网络,服务器)