码上敲享录 > linux系统常见问题 > java如何添加ip到iptable黑名单

java如何添加ip到iptable黑名单

上一章章节目录下一章 2018-08-01已有3230人阅读 评论(0)

java如何添加ip到iptable黑名单

解决方法:

String[] cmd = new String[] { "/bin/sh", "-c", "iptables -I INPUT -s 211.1.0.24 -j DROP;iptables -I INPUT -s 211.1.0.25 -j DROP" };

        try {

        Runtime.getRuntime().exec(cmd);

       } catch (Exception e) {

           e.printStackTrace();

       }finally {

       Runtime.getRuntime().exec("service iptables save");

}

iptables -I INPUT -s 211.1.0.24 -j DROP表示添加211.1.0.24到iptables黑名单中

iptables -I INPUT -s 211.1.0.24 -j DROP;iptables -I INPUT -s 211.1.0.25 -j DROP表示添加多个ip,多个ip使用分号隔开

service iptables save表示保存iptables,下次重启服务器时这次添加的ip黑名单还在。


本文地址:http://www.yayihouse.com/yayishuwu/chapter/1387


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交