Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eterban
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
eterban
Commits
a3f8fe16
Commit
a3f8fe16
authored
Mar 19, 2026
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gateway: make ipset maxelem configurable via settings.ini
Default 2000000, was hardcoded 650000.
parent
051276d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
29 deletions
+41
-29
settings.ini
common/etc/eterban/settings.ini
+6
-1
eterban_switcher.py
gateway/usr/share/eterban/eterban_switcher.py
+35
-28
No files found.
common/etc/eterban/settings.ini
View file @
a3f8fe16
...
@@ -8,9 +8,14 @@
...
@@ -8,9 +8,14 @@
# Input interface
# Input interface
#i_interface = brlocal
#i_interface = brlocal
# Seco
r
d input interface
# Seco
n
d input interface
#i_interface2 = brlocal2
#i_interface2 = brlocal2
# Internal interface (for blocking outgoing connections to banned IPs)
# When internal users access banned IPs on ports 80/443,
# traffic is redirected to ban_server (DNAT by destination, not source)
#internal_interface = vmbr0
#hostname = localhost
#hostname = localhost
# Maximum number of entries in ipset (default: 2000000)
# Maximum number of entries in ipset (default: 2000000)
...
...
gateway/usr/share/eterban/eterban_switcher.py
View file @
a3f8fe16
...
@@ -49,6 +49,7 @@ def parse_config (path_to_config, path_to_log):
...
@@ -49,6 +49,7 @@ def parse_config (path_to_config, path_to_log):
ban_server_ipv6
=
config
.
get
(
"Settings"
,
"ban_server_ipv6"
,
fallback
=
""
)
ban_server_ipv6
=
config
.
get
(
"Settings"
,
"ban_server_ipv6"
,
fallback
=
""
)
i_interface
=
config
.
get
(
"Settings"
,
"i_interface"
,
fallback
=
"i_interface"
)
i_interface
=
config
.
get
(
"Settings"
,
"i_interface"
,
fallback
=
"i_interface"
)
i_interface2
=
config
.
get
(
"Settings"
,
"i_interface2"
,
fallback
=
""
)
i_interface2
=
config
.
get
(
"Settings"
,
"i_interface2"
,
fallback
=
""
)
internal_interface
=
config
.
get
(
"Settings"
,
"internal_interface"
,
fallback
=
""
)
if
redis_server
==
"redis_server"
or
ban_server
==
"ban_server"
or
i_interface
==
"i_interface"
:
if
redis_server
==
"redis_server"
or
ban_server
==
"ban_server"
or
i_interface
==
"i_interface"
:
#config.set("Settings", "redis_server", "10.20.30.101")
#config.set("Settings", "redis_server", "10.20.30.101")
#with open(path_to_config, "w") as config_file:
#with open(path_to_config, "w") as config_file:
...
@@ -60,7 +61,7 @@ def parse_config (path_to_config, path_to_log):
...
@@ -60,7 +61,7 @@ def parse_config (path_to_config, path_to_log):
sys
.
exit
()
sys
.
exit
()
else
:
else
:
maxelem
=
config
.
getint
(
"Settings"
,
"maxelem"
,
fallback
=
2000000
)
maxelem
=
config
.
getint
(
"Settings"
,
"maxelem"
,
fallback
=
2000000
)
return
(
redis_server
,
ban_server
,
ban_server_ipv6
,
i_interface
,
i_interface2
,
maxelem
)
return
(
redis_server
,
ban_server
,
ban_server_ipv6
,
i_interface
,
i_interface2
,
internal_interface
,
maxelem
)
def
save_ipset_eterban_1
():
def
save_ipset_eterban_1
():
global
ipset_eterban_1
,
ipset_eterban_1_ipv6
,
ipset_firehol
,
ipset_eterban_white
,
path_to_eterban
global
ipset_eterban_1
,
ipset_eterban_1_ipv6
,
ipset_firehol
,
ipset_eterban_white
,
path_to_eterban
...
@@ -77,7 +78,7 @@ def restore_ipset_eterban_1():
...
@@ -77,7 +78,7 @@ def restore_ipset_eterban_1():
subprocess
.
call
(
command
,
shell
=
True
)
subprocess
.
call
(
command
,
shell
=
True
)
def
create_iptables_rules
():
def
create_iptables_rules
():
global
ban_server
,
ipset_eterban_1
,
ipset_firehol
,
ipset_eterban_white
,
i_interface
,
i_interface2
,
maxelem
global
ban_server
,
ipset_eterban_1
,
ipset_firehol
,
ipset_eterban_white
,
i_interface
,
i_interface2
,
internal_interface
,
maxelem
commands
=
[
'ipset create '
+
ipset_eterban_1
+
' hash:ip maxelem '
+
str
(
maxelem
),
commands
=
[
'ipset create '
+
ipset_eterban_1
+
' hash:ip maxelem '
+
str
(
maxelem
),
'ipset create '
+
ipset_firehol
+
' hash:net'
,
'ipset create '
+
ipset_firehol
+
' hash:net'
,
'ipset create '
+
ipset_eterban_white
+
' hash:ip'
,
'ipset create '
+
ipset_eterban_white
+
' hash:ip'
,
...
@@ -90,18 +91,22 @@ def create_iptables_rules():
...
@@ -90,18 +91,22 @@ def create_iptables_rules():
for
command
in
commands
:
for
command
in
commands
:
subprocess
.
call
(
command
,
shell
=
True
)
subprocess
.
call
(
command
,
shell
=
True
)
if
not
i_interface2
:
if
i_interface2
:
return
commands
=
[
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_white
+
' src -j ACCEPT'
,
'iptables -I FORWARD -i '
+
i_interface2
+
' -p tcp -m multiport ! --dport 80,81,443 -m set --match-set '
+
ipset_eterban_1
+
' src -j REJECT'
]
for
command
in
commands
:
subprocess
.
call
(
command
,
shell
=
True
)
commands
=
[
# Internal interface: block outgoing connections to banned IPs (DNAT by destination)
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
if
internal_interface
:
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
commands
=
[
'iptables -t nat -I PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_white
+
' src -j ACCEPT'
,
'iptables -t nat -I PREROUTING -i '
+
internal_interface
+
' -m set --match-set '
+
ipset_eterban_1
+
' dst -p tcp -m multiport --dports 80,443 -j DNAT --to-destination '
+
ban_server
+
':82'
,
#'iptables -t nat -I PREROUTING -i ' + i_interface2 + ' -m set ! --match-set ' + ipset_eterban_1 + ' src -d ' + ban_server + ' -p tcp -m multiport --destination-port 80,443 -j DNAT --to-destination ' + ban_server + ':81',
'iptables -t nat -I PREROUTING -i '
+
internal_interface
+
' -m set --match-set '
+
ipset_firehol
+
' dst -p tcp -m multiport --dports 80,443 -j DNAT --to-destination '
+
ban_server
+
':82'
]
#'iptables -t nat -I PREROUTING -i ' + i_interface2 + ' -m set --match-set ' + ipset_eterban_1 + ' src -p tcp --dport 443 -j DNAT --to-destination ' + ban_server + ':80',
for
command
in
commands
:
'iptables -I FORWARD -i '
+
i_interface2
+
' -p tcp -m multiport ! --dport 80,81,443 -m set --match-set '
+
ipset_eterban_1
+
' src -j REJECT'
]
subprocess
.
call
(
command
,
shell
=
True
)
for
command
in
commands
:
subprocess
.
call
(
command
,
shell
=
True
)
def
create_ip6tables_rules
():
def
create_ip6tables_rules
():
...
@@ -135,7 +140,7 @@ def create_ip6tables_rules():
...
@@ -135,7 +140,7 @@ def create_ip6tables_rules():
def
destroy_iptables_rules
():
def
destroy_iptables_rules
():
global
ban_server
,
ipset_eterban_1
,
ipset_firehol
,
ipset_eterban_white
,
i_interface
,
i_interface2
global
ban_server
,
ipset_eterban_1
,
ipset_firehol
,
ipset_eterban_white
,
i_interface
,
i_interface2
,
internal_interface
commands
=
[
commands
=
[
'iptables -t nat -D PREROUTING -i '
+
i_interface
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -D PREROUTING -i '
+
i_interface
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -D PREROUTING -i '
+
i_interface
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -D PREROUTING -i '
+
i_interface
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
...
@@ -150,20 +155,22 @@ def destroy_iptables_rules ():
...
@@ -150,20 +155,22 @@ def destroy_iptables_rules ():
subprocess
.
call
(
command
,
shell
=
True
)
subprocess
.
call
(
command
,
shell
=
True
)
#print (command)
#print (command)
if
not
i_interface2
:
if
i_interface2
:
return
commands
=
[
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
commands
=
[
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_firehol
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_white
+
' src -j ACCEPT'
,
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_1
+
' src -j DNAT --to-destination '
+
ban_server
,
'iptables -D FORWARD -i '
+
i_interface2
+
' -p tcp -m multiport ! --dport 80,81,443 -m set --match-set '
+
ipset_eterban_1
+
' src -j REJECT'
]
'iptables -t nat -D PREROUTING -i '
+
i_interface2
+
' -m set --match-set '
+
ipset_eterban_white
+
' src -j ACCEPT'
,
for
command
in
commands
:
#'iptables -t nat -D PREROUTING -i ' + i_interface + ' -m set ! --match-set ' + ipset_eterban_1 + ' src -d ' + ban_server + ' -p tcp -m multiport --destination-port 80,443 -j DNAT --to-destination ' + ban_server + ':81',
subprocess
.
call
(
command
,
shell
=
True
)
#'iptables -t nat -D PREROUTING -i ' + i_interface + ' -m set --match-set ' + ipset_eterban_1 + ' src -p tcp --dport 443 -j DNAT --to-destination ' + ban_server + ':80',
'iptables -D FORWARD -i '
+
i_interface2
+
' -p tcp -m multiport ! --dport 80,81,443 -m set --match-set '
+
ipset_eterban_1
+
' src -j REJECT'
]
for
command
in
commands
:
# Internal interface: remove outgoing block rules
subprocess
.
call
(
command
,
shell
=
True
)
if
internal_interface
:
#print (command)
commands
=
[
'iptables -t nat -D PREROUTING -i '
+
internal_interface
+
' -m set --match-set '
+
ipset_eterban_1
+
' dst -p tcp -m multiport --dports 80,443 -j DNAT --to-destination '
+
ban_server
+
':82'
,
'iptables -t nat -D PREROUTING -i '
+
internal_interface
+
' -m set --match-set '
+
ipset_firehol
+
' dst -p tcp -m multiport --dports 80,443 -j DNAT --to-destination '
+
ban_server
+
':82'
]
for
command
in
commands
:
subprocess
.
call
(
command
,
shell
=
True
)
def
destroy_ip6tables_rules
():
def
destroy_ip6tables_rules
():
...
@@ -216,7 +223,7 @@ signal.signal(signal.SIGTERM, exit_gracefully)
...
@@ -216,7 +223,7 @@ signal.signal(signal.SIGTERM, exit_gracefully)
#print ('1')
#print ('1')
redis_server
,
ban_server
,
ban_server_ipv6
,
i_interface
,
i_interface2
,
maxelem
=
parse_config
(
path_to_config
,
path_to_log
)
redis_server
,
ban_server
,
ban_server_ipv6
,
i_interface
,
i_interface2
,
internal_interface
,
maxelem
=
parse_config
(
path_to_config
,
path_to_log
)
#destroy_iptables_rules ()
#destroy_iptables_rules ()
#sys.exit()
#sys.exit()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment