42 lines
1.5 KiB
Bash
42 lines
1.5 KiB
Bash
# =============================================================================
|
|
# autoIpTables.sh
|
|
#
|
|
# Setup multiple IpTables incoming and outgoing port mappings for easy setup.
|
|
#
|
|
# Copyright (c) 2025 VELENDEU, eetnaviation
|
|
#
|
|
# https://velend.eu/
|
|
# https://git.velend.eu/eetnaviation/shscripts
|
|
#
|
|
# All rights reserved unless otherwise stated.
|
|
#
|
|
# Permission is hereby denied to copy, modify, distribute, sublicense,
|
|
# or sell copies of this software without explicit prior written consent.
|
|
#
|
|
# All dependency trademarks and names if included are subject to copyright
|
|
# of their respective owners.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
# THE SOFTWARE.
|
|
# =============================================================================
|
|
|
|
#!/bin/bash
|
|
|
|
declare -A PORT_MAPS=( # Write your ports in here, example [80]=1234 would direct outside port 80 to inside port 1234
|
|
[80]=1234
|
|
)
|
|
|
|
# Apply iptables rule for each mapping
|
|
for outsidePort in "${!PORT_MAPS[@]}"; do
|
|
insidePort="${PORT_MAPS[$outsidePort]}"
|
|
iptables -t nat -A PREROUTING -p tcp --dport "$outsidePort" -j REDIRECT --to-port "$insidePort"
|
|
done
|
|
|
|
# Display all mappings
|
|
iptables -t nat -L -v -n
|