chainfear
asked on
getting dynamic ip on linux and pass to iptables script
Hi,
I need to pass IP to iptables script and tried below method, and it works:
/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
However, when I tried to use it in my script:
#!/bin/sh
IPT="/sbin/iptables"
IF=eth0
ETH0=/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
$IPT -A INPUT -s 0/0 -i $IF -d $ETH0 -p TCP --dport 22 -m state --state NEW -j ACCEPT
I keep getting:
eth0: not found
I missed out anything? Is this even the right way?
Thanks in advanced!
I need to pass IP to iptables script and tried below method, and it works:
/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
However, when I tried to use it in my script:
#!/bin/sh
IPT="/sbin/iptables"
IF=eth0
ETH0=/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
$IPT -A INPUT -s 0/0 -i $IF -d $ETH0 -p TCP --dport 22 -m state --state NEW -j ACCEPT
I keep getting:
eth0: not found
I missed out anything? Is this even the right way?
Thanks in advanced!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome :)
ASKER