---
title: "Bash Script"
type: "forum-thread"
url: "https://www.webforum.nu/amne/linux-bsd/64569-bash-script"
topic: "Linux & BSD"
topic_url: "https://www.webforum.nu/amne/linux-bsd"
author: "Viktor"
published: "2003-01-12T14:32:32.000Z"
updated: "2003-01-14T09:02:07.000Z"
replies: 1
views: 222
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/linux-bsd/64569-bash-script"
---

# Bash Script

## #1 — Viktor, 2003-01-12T14:32Z

Får inte ett bash skript att fungera :(

```
#!/bin/bash

EXTERNAL_IP=xxx.xxx.xxx.xxx
INTERNAL_IP=192.168.0.1
INTERNAL_INTERFACE=eth0
EXTERNAL_INTERFACE=eth1
INTERNAL_NETWORK=192.168.0.0/24

# extract the ips and port
NAT_EXT_PORT=$1
NAT_INT_IP=192.168.0.99
NAT_INT_PORT=$1
PROTOCOL=$2
# write the rules!

# this is the prerouting dnat
#iptables -A PREROUTING -t nat -p $PROTOCOL -d $EXTERNAL_IP --dport $NAT_EXT_PORT -j DNAT --to-destination $NAT_INT_IP:$NAT_\
INT_PORT

# This allows packets from external->internal
iptables -A FORWARD -i $EXTERNAL_INTERFACE -o $INTERNAL_INTERFACE -p $PROTOCOL  -d $NAT_INT_IP --dport $NAT_INT_PORT -m sta\
te --state NEW,ESTABLISHED,RELATED -j ACCEPT

# This allows packets from internal->external
iptables -A FORWARD -i $INTERNAL_INTERFACE -o $EXTERNAL_INTERFACE -p $PROTOCOL -s $NAT_INT_IP --sport $NAT_INT_PORT -m stat\
e --state NEW,ESTABLISHED,RELATED -j ACCEPT

# This enables access to the 'public' server from the internal network
iptables -t nat -A POSTROUTING -d $NAT_INT_IP -s $INTERNAL_NETWORK -p $PROTOCOL --dport $NAT_INT_PORT -j SNAT --to $INTERNA\
L_IP

echo firewall: dnat: $EXTERNAL_IP:$NAT_EXT_PORT - $NAT_INT_IP:$NAT_INT_PORT
```

När jag kör det så får jag felmedelandet 

> \[root@celeron portforward\]# bash ./portforward.sh 3297 tcp
> 
> ' specified.2.5: unknown protocol \`tcp
> Try \`iptables -h' or 'iptables --help' for more information.
> ' (No aliases, :, ! or \*).n interface \`eth1
> ' (No aliases, :, ! or \*).n interface \`eth0
> ' specified.2.5: unknown protocol \`tcp
> Try \`iptables -h' or 'iptables --help' for more information.
> ' (No aliases, :, ! or \*).n interface \`eth0
> ' (No aliases, :, ! or \*).n interface \`eth1
> ' specified.2.5: unknown protocol \`tcp
> Try \`iptables -h' or 'iptables --help' for more information.
> ' specified.2.5: unknown protocol \`tcp
> Try \`iptables -h' or 'iptables --help' for more information.
> :32972.168.0.99 xxx.xxx.xxx.xxx

När jag kör allt manuellt så fungerar det perfekt.

/Viktor

Permalänk: https://www.webforum.nu/p/64569

## #2 — RanXeroX, 2003-01-14T09:02Z

Kanske måste peka vart iptables ligger någonstans ?

t.ex. 
iptables=/usr/bin/iptables

// ranxerox

Permalänk: https://www.webforum.nu/p/911965

---

Tråden på webben: https://www.webforum.nu/amne/linux-bsd/64569-bash-script
