View previous topic :: View next topic |
Author |
Message |
pokey909 n00b
Joined: 19 Nov 2004 Posts: 10
|
Posted: Sat Jan 22, 2005 9:16 pm Post subject: iptables dynamic source ip |
|
|
Hi!
Basic problem: I'm trying to open a port of box A just for one other box B which has a dynamic IP but can be identified via dyndns,
I was trying to specify a rule with a source coming from a dynamic dns (like bla.dyndns.org). When I type iptables -L this name is substituted with the dynamic dns of my provider and it remains there! So if my box (the one with the dynamic dns) does down and up again, the bla.dyndns.org show the correct ip. But since iptables stored the dns from the provider it doesnt resolve to my box anymore.
Any solution how to fix that? |
|
Back to top |
|
|
Randseed Tux's lil' helper
Joined: 01 Apr 2004 Posts: 111
|
Posted: Sat Jan 22, 2005 9:41 pm Post subject: |
|
|
I have similar problems with my network setup. Probably the best way to deal with it is to have one box ping the dynamic box on some kind of specialty protocol. For example, just write a daemon that you can connect to through stunnel that just returns its IP address. If one box can't connect to the dynamic box, then a script resets the firewall rules.
A simpler option is to run a script on the first machine that periodically compares the dynamic address resolution to the stored IP. If it is different, it kills the old rules and inserts new ones reflecting the new address.
Unfortunately, the Internet was never really designed for dynamic IP addresses in the first place, so in general they're just a royal pain in the ass. |
|
Back to top |
|
|
pokey909 n00b
Joined: 19 Nov 2004 Posts: 10
|
Posted: Sat Jan 22, 2005 10:19 pm Post subject: |
|
|
poor iptables
maybe now its the time to think about a vpn... |
|
Back to top |
|
|
Randseed Tux's lil' helper
Joined: 01 Apr 2004 Posts: 111
|
Posted: Mon Jan 31, 2005 8:13 pm Post subject: |
|
|
pokey909 wrote: | poor iptables
maybe now its the time to think about a vpn... |
That's actually what I do, and it solves the problem. The office servers connect with a cable modem so they have a fairly stable IP, but I use a dynamic DNS service for the cases when the IP changes. I fondly remember running nmap on the entire Class C once to find my machine. Never again. |
|
Back to top |
|
|
thebigslide l33t
Joined: 23 Dec 2004 Posts: 792 Location: under a car or on top of a keyboard
|
Posted: Mon Jan 31, 2005 8:28 pm Post subject: |
|
|
You need to make a cron job that digs the hostname to get the IP. Then use sed to run an iptables command that updates that rule (they are numbered and you can just update that one.
What is the iptables rule you're doing right now and it's rule number and the hostname and I'll write the script for you. Just remember the script may need updating (to update the rule number) if you update your firewall at any time. |
|
Back to top |
|
|
teknomage1 Veteran
Joined: 05 Aug 2003 Posts: 1239 Location: Los Angeles, CA
|
Posted: Mon Jan 31, 2005 11:19 pm Post subject: |
|
|
you can also set your system to email you the ip address every time it reboots.
Here's a perl script: Code: | #!/usr/bin/perl
$city = "Savannah";
chomp($hostname = `/bin/hostname`);
$ifconfig = join("\n", `/sbin/ifconfig`);
$date = `date`;
while ($ifconfig =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g) {
$snag = $1;
print " $date $hostname in $city has reset. The current IP is $snag \n" unless ($snag =~ m/^(?:255)|(?:192\.168)|(?:172\.[1-3][\d])|(?:127\.0\.0)/m) or ($snag =~ m/255$/);
} | Put a line to call the script and pipe the output to mail in /etc/conf.d/local.start. To really get things automated you could have it email the other machine and then use procmail to set the routing info. |
|
Back to top |
|
|
CriminalMastermind Tux's lil' helper
Joined: 19 Nov 2003 Posts: 132 Location: toronto
|
Posted: Tue Feb 01, 2005 7:52 am Post subject: |
|
|
you could use the tcpd wraper to restrict access to this service, wrather then using iptables. it's in sys-apps/tcp-wrappers. the app you are using would have to be tcpd enabled. there is a USE flag for this, so you may need to re-compiling the app.
there is no iptable match function that resolves dns name at the time of access. at least not to my knowledge. the name is resolved by the iptables command and the ip address is put into the table, not the dns name.
as thebigslide suggested, a cron job would also work, but if you had bad luck, you may still get locked out of your box while you wait for your cron job to run. i'd be very careful with any automated script that modified my firewall. it could be quite bad if it deleted the wrong rule by accident. you may want to check out this
last but not least, you could use port knocking to only accept connections to the service from those that know the right "knock". i've never used this, but i'm sure there is plenty of info and scripts to do it.
hope that helped _________________ "I can picture a perfect world that knows of no war... and I can picture me attacking that world, because they'd never expect it." |
|
Back to top |
|
|
urcindalo l33t
Joined: 08 Feb 2005 Posts: 623 Location: Almeria, Spain
|
Posted: Sat Apr 08, 2006 8:18 am Post subject: |
|
|
thebigslide wrote: | You need to make a cron job that digs the hostname to get the IP. Then use sed to run an iptables command that updates that rule (they are numbered and you can just update that one.
What is the iptables rule you're doing right now and it's rule number and the hostname and I'll write the script for you. Just remember the script may need updating (to update the rule number) if you update your firewall at any time. |
I'm having the very same problem and am looking for the solution you proposed. Here is the part of my iptables.conf regarding the dynamic address: Code: | # accept from home
-A INPUT -s myname.no-ip.org -j ACCEPT
-A OUTPUT -s myname.no-ip.org -j ACCEPT |
And here is the output of my running iptables: Code: | $ sudo iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 127.0.0.1 0.0.0.0/0
ACCEPT all -- XX.XX.114.34 0.0.0.0/0
ACCEPT all -- [static ip] 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:20
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:21
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:137:139
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:426
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:445
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:1417:1420
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:5900:5902
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpts:5900:5902
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:5800:5802
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpts:5800:5802
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:5500:5502
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpts:5500:5502
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- XX.XX.114.34 0.0.0.0/0
ACCEPT all -- [static ip] 0.0.0.0/0 |
The box myname.no-ip.org appears as XX.XX.114.34 in iptables, when it is XX.XX.119.153 right now.
May I take the word you gave pokey909 and kindly ask you for that script? Thanks very much in advance. |
|
Back to top |
|
|
|