用 ipset 和 iptables 保护 sip 端口

这里先假定 sip 端口是 5060 和 5080

cat china.sh,and ./china.sh

#!/bin/bash

apt install -y ipset

ipset destroy china

ipset create china hash:net maxelem 65536

ipset flush china

wget --no-check-certificate -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", 4, 32-log(5)/log(2)) }' > /etc/china.txt

while read ip; do

/sbin/ipset add china $ip

done < /etc/china.txt

ipset add china 192.168.0.0/16

ipset add china 172.16.0.0/12

ipset add china 10.0.0.0/8

ipset save china > ./china.conf

设置下面几条 iptables 规则:

iptables -A INPUT -p udp --dport 5060:5080 -m set --match-set china src -j ACCEPT

iptables -A INPUT -p udp --dport 5060:5080 -j DROP

iptables -A INPUT -p tcp --dport 5060:5080 -m set --match-set china src -j ACCEPT

iptables -A INPUT -p tcp --dport 5060:5080 -j DROP

iptables-save > ./iprule.conf

最后一个问题是开机后自动生效

cat /lib/systemd/system/rc-local.service

该服务的生效条件为 /etc/rc.local 有可执行的属性,剩下的就简单了,不再赘述

相关推荐
ysdysyn2 个月前
C# Modbus RTU 多从站控制全攻略:一端口,双轴控制
开发语言·c#·mvvm·通讯·modbus rtu
SunkingYang2 个月前
MFC进程间消息传递:SendMessage、PostMessage与SendNotifyMessage分别如何实现,进程间通讯需要注意哪些问题
c++·mfc·通讯·postmessage·sendmessage·sendnotify·进程间
SunkingYang2 个月前
QT程序如何将事件和消息发送给MFC程序,MFC程序如何接收消息和事件
qt·mfc·消息·事件·通信·通讯·传递
B_lack0263 个月前
Wincc画面通讯故障判断
上位机·通讯·西门子plc·wincc
brave and determined3 个月前
接口通讯学习(day04):RS-232与RS-485:通信接口全解析
网络·uart·通讯·emc·rs232·rs485·嵌入式设计
研华科技Advantech3 个月前
构建自主可控“数字网络”,重塑新能源汽车智能产线高可靠实时通讯
汽车·新能源·通讯·智能产线
张人玉4 个月前
VsionMaster筛选机错误情况
数码相机·c#·通讯·网络通讯
张人玉4 个月前
c#串口读写威盟士五插针
开发语言·c#·通讯
好望角雾眠6 个月前
第四阶段C#通讯开发-1:通讯基础理论,串口,通讯模式,单位转换,代码示例
开发语言·笔记·c#·串口·通讯
专业机床数据采集9 个月前
宝元LNC数控数据采集方式、跨平台采集通讯方案介绍
cnc·通讯·采集·数控·宝元lnc