Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDR Improvements: Allow TO/FROM+INTERACE+IP STACK #765

Open
wants to merge 81 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
381d095
Allow setting custom interface when doing "rdr"
tschettervictor Dec 9, 2024
dc9822a
also list interface when doing "list all" for published ports
tschettervictor Dec 10, 2024
1c807bb
Add docs about RDR multiple interfaces
tschettervictor Dec 10, 2024
2b6a7e8
add new interface option to docs
tschettervictor Dec 10, 2024
bafa183
remove unecessary "echo"
tschettervictor Dec 10, 2024
eb65800
show output when creating rdr rule
tschettervictor Dec 10, 2024
622d84b
allow specifying IP to redirect traffic to
tschettervictor Dec 11, 2024
471a91c
print IP in addition to interface when listing RDR
tschettervictor Dec 11, 2024
035855b
major rewrite to allow setting TO+FROM
tschettervictor Dec 11, 2024
d21b516
add usage command with new switches
tschettervictor Dec 11, 2024
f627aad
spacing
tschettervictor Dec 11, 2024
7f1be3d
more spacing
tschettervictor Dec 11, 2024
2cff404
document new changes to rdr
tschettervictor Dec 11, 2024
4b56554
add protocol to printed info
tschettervictor Dec 11, 2024
5b7b848
revert listing of IP and interface
tschettervictor Dec 11, 2024
9ce301b
spacing
tschettervictor Dec 11, 2024
ac8d71b
Update rdr.rst
tschettervictor Dec 11, 2024
02e76f5
Update rdr.rst
tschettervictor Dec 11, 2024
356840a
Update rdr.rst
tschettervictor Dec 11, 2024
a52b53d
spacing
tschettervictor Dec 11, 2024
e5acf6f
spacing
tschettervictor Dec 11, 2024
8f3ad2f
change to -ge 6
tschettervictor Dec 11, 2024
74eab24
add error notify to pfctl commands/add better info commands
tschettervictor Dec 11, 2024
53b4730
better error handling
tschettervictor Dec 11, 2024
4984f68
Update docs
tschettervictor Dec 11, 2024
6945781
Add /
tschettervictor Dec 11, 2024
492b64b
fix help usage command
tschettervictor Dec 12, 2024
449a0ae
add check when setting source IP + supress echo output
tschettervictor Dec 12, 2024
606d8da
only persist rdr rule if it can be properly loaded, else exit
tschettervictor Dec 12, 2024
7ab9188
Use case command instead of getopts to remain consistent
tschettervictor Dec 13, 2024
4377e14
help message conform to case command
tschettervictor Dec 13, 2024
c6547e9
help message docs
tschettervictor Dec 13, 2024
ab54842
error handling + add reset command to remove all rdr rules
tschettervictor Dec 13, 2024
9b62613
Update rdr.rst - add reset to help
tschettervictor Dec 13, 2024
20a291c
add reset to help command
tschettervictor Dec 13, 2024
d6cbbf2
quick fix
tschettervictor Dec 13, 2024
3f97dd7
split options and regular case commands
tschettervictor Dec 13, 2024
216a4a5
spacing
tschettervictor Dec 13, 2024
ae9a33a
error handling
tschettervictor Dec 13, 2024
ebf9c89
missing done
tschettervictor Dec 13, 2024
3a16c04
merge case commands, better error handling
tschettervictor Dec 13, 2024
29bd130
final revision
tschettervictor Dec 13, 2024
0ce5c27
add small info to reset command
tschettervictor Dec 13, 2024
744dd10
remove .
tschettervictor Dec 13, 2024
1fcdfa4
add "ports" command to list jails and their published ports
tschettervictor Dec 13, 2024
8bf7342
remove / to stay consistent
tschettervictor Dec 13, 2024
e6ae0eb
too much green, minimize color and info when redirecting
tschettervictor Dec 13, 2024
7cb3e4a
fix ip6 rule syntax
tschettervictor Dec 14, 2024
9d37a15
revert/ persist first then load rule
tschettervictor Dec 14, 2024
031f47f
fix ipv6 (inet > inet6)
tschettervictor Dec 14, 2024
5b4cb72
add support for dual/ipv4/ipv6 options
tschettervictor Dec 14, 2024
2059560
list stack when listing ports
tschettervictor Dec 14, 2024
981268c
document -t
tschettervictor Dec 14, 2024
1f899b7
add space to list command
tschettervictor Dec 14, 2024
bd2a2e1
Typo
tschettervictor Dec 14, 2024
afd7ea7
Typo
tschettervictor Dec 14, 2024
85fecea
var rename for clarity
tschettervictor Dec 15, 2024
71b1f8c
simply print rdr file when listing ports
tschettervictor Dec 15, 2024
a717b09
print less info
tschettervictor Dec 15, 2024
05e0eb2
Merge branch 'master' into rdr-multiple-interfaces
tschettervictor Dec 16, 2024
0c80326
fix quotes
tschettervictor Dec 16, 2024
2669d81
Merge branch 'master' into rdr-multiple-interfaces
tschettervictor Dec 17, 2024
fd4c511
cleanup
tschettervictor Dec 17, 2024
33b3c18
Merge branch 'BastilleBSD:master' into rdr-multiple-interfaces
tschettervictor Jan 5, 2025
0501dc5
Merge branch 'BastilleBSD:master' into rdr-multiple-interfaces
tschettervictor Jan 7, 2025
6f0d318
rdr: Add debug option, code cleanup
tschettervictor Jan 7, 2025
ada6c2d
rdr: correctly print default interface IP
tschettervictor Jan 8, 2025
a169beb
rdr: do not allow rules to be duplicated between jails
tschettervictor Jan 8, 2025
b7c861f
rdr: clear > reset notify on duplicate jail rules
tschettervictor Jan 8, 2025
e5f5655
rdr: Allow only a single target
tschettervictor Jan 8, 2025
2da817e
list: use list command for jail list
tschettervictor Jan 8, 2025
eee99a3
rdr: fix _jail > TARGET + alphabetical option order
tschettervictor Jan 8, 2025
685c8f9
doc: rdr with multiple interfaces
tschettervictor Jan 8, 2025
cab6ef8
Merge branch 'BastilleBSD:master' into rdr-multiple-interfaces
tschettervictor Jan 11, 2025
780f93c
rdr: spacing fix and usage message remove additional ]
tschettervictor Jan 11, 2025
ba50618
docs: update rdr docs with code block for options
tschettervictor Jan 11, 2025
0696152
docs: rdr, fix info return block
tschettervictor Jan 11, 2025
cf3bb4e
rdr: fix echo code on IPv6 redirection
tschettervictor Jan 11, 2025
0a837ee
rdr: support old style interface
tschettervictor Jan 12, 2025
254f171
rdr: update error_message to say reset instead of clear
tschettervictor Jan 12, 2025
bee0501
rdr: trim subnet in case it is included behind ip
tschettervictor Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions docs/chapters/subcommands/rdr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,67 @@ specify the interface they run on in rc.conf (or other config files)
.. code-block:: shell

# bastille rdr --help
Usage: bastille rdr TARGET [clear] | [list] | [tcp <host_port> <jail_port>] | [udp <host_port> <jail_port>]
Usage: bastille rdr TARGET [option(s)] [clear|reset|list|(tcp|udp host_port jail_port [log ['(' logopts ')'] ] )]
Options:

-i | --interface [interface] Set the interface to create the rdr rule on. Useful if you have multiple interfaces.
-s | --source [source ip] Limit rdr to a source IP. Useful to only allow access from a certian IP or subnet.
-d | --destination [destination ip] Limit rdr to a destination IP. Useful if you have multiple IPs on one interface.
-t | --type [ipv4|ipv6] Specify IP type. Must be used if -s or -d are used. Defaults to both.
-x | --debug Enable debug mode.

# bastille rdr dev1 tcp 2001 22
[jail1]:
IPv4 tcp/2001:22 on em0

# bastille rdr dev1 list
rdr on em0 inet proto tcp from any to any port = 2001 -> 10.17.89.1 port 22

# bastille rdr dev1 udp 2053 53
[jail1]:
IPv4 udp/2053:53 on em0

# bastille rdr dev1 list
rdr on em0 inet proto tcp from any to any port = 2001 -> 10.17.89.1 port 22
rdr on em0 inet proto udp from any to any port = 2053 -> 10.17.89.1 port 53
rdr pass on em0 inet proto tcp from any to any port = 2001 -> 10.17.89.1 port 22
rdr pass on em0 inet proto udp from any to any port = 2053 -> 10.17.89.1 port 53

# bastille rdr dev1 clear
nat cleared

The `rdr` command includes 4 additional options:

.. code-block:: shell

-i | --interface [interface] Set the interface to create the rdr rule on. Useful if you have multiple interfaces.
-s | --source [source ip] Limit rdr to a source IP. Useful to only allow access from a certian IP or subnet.
-d | --destination [destination ip] Limit rdr to a destination IP. Useful if you have multiple IPs on one interface.
-t | --type [ipv4|ipv6] Specify IP type. Must be used if -s or -d are used. Defaults to both.

.. code-block:: shell

# bastille rdr dev1 -i vtnet0 udp 8000 80
[jail1]:
IPv4 tcp/8000:80 on vtnet0

# bastille rdr dev1 -s 192.168.0.1 tcp 8080 81
[jail1]:
IPv4 tcp/8080:81 on em0

# bastille rdr dev1 -d 192.168.0.84 tcp 8082 82
[jail1]:
IPv4 tcp/8082:82 on em0

# bastille rdr dev1 -i vtnet0 -d 192.168.0.45 tcp 9000 9000
[jail1]:
IPv4 tcp/9000:9000 on vtnet0

# bastille rdr dev1 list
rdr pass on vtnet0 inet proto udp from any to any port = 2001 -> 10.17.89.1 port 22
rdr pass on em0 inet proto tcp from 192.168.0.1 to any port = 8080 -> 10.17.89.1 port 81
rdr pass on em0 inet proto tcp from any to 192.168.0.84 port = 8082 -> 10.17.89.1 port 82
rdr pass on vtnet0 inet proto tcp from any to 192.168.0.45 port = 9000 -> 10.17.89.1 port 9000

The options can be used together, as seen above.

If you have multiple interfaces assigned to your jail, `bastille rdr` will
only redirect using the default one.
18 changes: 17 additions & 1 deletion usr/local/share/bastille/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
. /usr/local/etc/bastille/bastille.conf

usage() {
error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|(import|export|backup)]"
error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|ports|(import|export|backup)]"
}

if [ "${1}" = help ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then
Expand Down Expand Up @@ -227,12 +227,28 @@ list_import(){
ls "${bastille_backupsdir}" | grep -v ".sha256$"
}

list_ports(){
if [ -d "${bastille_jailsdir}" ]; then
JAIL_LIST="$(bastille list jails)"
for _jail in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_jail}/rdr.conf" ]; then
_PORTS="$(cat ${bastille_jailsdir}/${_jail}/rdr.conf)"
info "[${_jail}]:"
echo "${_PORTS}"
fi
done
fi
}

if [ $# -gt 0 ]; then
# Handle special-case commands first.
case "${1}" in
all|-a|--all)
list_all
;;
port|ports)
list_ports
;;
release|releases)
list_release "${2}"
;;
Expand Down
Loading