EXTERN_IP variable?

EXTERN_IP variable?

Post by Chris Coope » Tue, 26 Sep 2000 04:00:00



I'm using PPP on eth1 (eth0 is internal network) to connect to the
internet, so my IP keeps changing.  How would I go about pulling the
current ip out so I could use it in setting up firewall rules
automatically?  I'm using ipmasqadm
                            Thanks
 
 
 

EXTERN_IP variable?

Post by Shining Knigh » Tue, 26 Sep 2000 04:00:00


A personal favorite is to determine the first default route interface and
then the address it is using although you could omit the first step if the
interface is fixed.  You will also want to make sure it is defined to be
something if, say, a dhcp address has not yet been obtained, and to restart
it when one is.  On RH6.1 2.2:

INTERFACE=`/sbin/route | grep 'default' | awk '{print NR " " $8}' | grep '1
' | awk '{print $2}'`
IPADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | awk '{print $2}' |
sed -e 's/.*://'`


Quote:> I'm using PPP on eth1 (eth0 is internal network) to connect to the
> internet, so my IP keeps changing.  How would I go about pulling the
> current ip out so I could use it in setting up firewall rules
> automatically?  I'm using ipmasqadm
>                             Thanks


 
 
 

EXTERN_IP variable?

Post by Lew Pitche » Wed, 27 Sep 2000 04:00:00



> I'm using PPP on eth1 (eth0 is internal network) to connect to the
> internet, so my IP keeps changing.  How would I go about pulling the
> current ip out so I could use it in setting up firewall rules
> automatically?  I'm using ipmasqadm
>                             Thanks

My favourite way is to have the /etc/ppp/ip-up script put the ip
address into a file. /etc/ppp/ip-down can delete the file when the
connection disconnects, so the file acts as both a sentinal as to the
availability of your ppp connection, and a storage place for it's
address.

Here's what (in part) my /etc/ppp/ip-up looks like...
  #
  #       ip-up Interface Device Speed Our_ip Isp_ip
  #=================================================
  # Record a sentinal file
  echo $4 >/var/run/$1.ip

Here's what (in part) my /etc/ppp/ip-down looks like...
  #!/bin/bash
  #
  #       ip-down Interface Device Speed Our_ip Isp_ip
  #
  #=================================================
  # Delete the sentinal file
  rm /var/run/$1.ip

To check if my ppp0 interface is up, I
  test -f /var/run/ppp0.ip

To check what my ppp0 IP address is, I
  cat /var/run/ppp0.ip

--
Lew Pitcher

Master Codewright and JOAT-in-training

 
 
 

EXTERN_IP variable?

Post by Lew Pitch » Thu, 28 Sep 2000 04:00:00





>> I'm using PPP on eth1 (eth0 is internal network) to connect to the
>> internet, so my IP keeps changing.  How would I go about pulling the
>> current ip out so I could use it in setting up firewall rules
>> automatically?  I'm using ipmasqadm
>>                             Thanks

>My favourite way is to have the /etc/ppp/ip-up script put the ip
>address into a file. /etc/ppp/ip-down can delete the file when the
>connection disconnects, so the file acts as both a sentinal as to the
>availability of your ppp connection, and a storage place for it's
>address.

>Here's what (in part) my /etc/ppp/ip-up looks like...
>  #
>  #       ip-up Interface Device Speed Our_ip Isp_ip
>  #=================================================
>  # Record a sentinal file
>  echo $4 >/var/run/$1.ip

>Here's what (in part) my /etc/ppp/ip-down looks like...
>  #!/bin/bash
>  #
>  #       ip-down Interface Device Speed Our_ip Isp_ip
>  #
>  #=================================================
>  # Delete the sentinal file
>  rm /var/run/$1.ip

>To check if my ppp0 interface is up, I
>  test -f /var/run/ppp0.ip

>To check what my ppp0 IP address is, I
>  cat /var/run/ppp0.ip

I should have noted that, since /etc/ppp/ip-up is run when the ppp
connection is established, and /etc/ppp/ip-down is run when the ppp
connection is terminated, and both scripts supply such details as
interface name and ip address, they make ideal places to incorporate
your ppp firewalling/masquerading rules.

If you feel uncomfortable placing your ipmasqadm rules into these
scripts, why not isolate the rules into another script that takes the
ip address (and/or interface name) as an argument, and invoke this
script from ip-up?

Lew Pitcher
Information Technology Consultant
Toronto Dominion Bank Financial Group


(Opinions expressed are my own, not my employer's.)