How to get pppd inet address from command line

I'm not sure if posting it here or at ServerFault. Anyway, I am trying to work with the company firewall to connect to another media sharing site using my 3g phone network. I came up with a simple ip route command that takes the address of inppdd as a parameter. But I want to make it a little more automated by reading the inet address directly from the script rather than passing it through a command line parameter.

Here's a script to make it more obvious:

  • Calling the command at the moment: $jumpfirewall xxx.xxx.xxx.xxx

  • Command call I want: $jumpfirewall

Do you know any command or library that I can use to read it from the command line?

+2


source to share


2 answers


Adapted from cyberciti :

/sbin/ifconfig ppp0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
      



ifconfig ppp0

get information for your main PPP interface; grep

truncates it to a string containing the IP address; cut

separates everything after inet addr:

before bcast:

, giving something like 1.2.3.4 Bcast:

; and the call awk

will only print the first (space-separated) field, leaving you with only the IP address.

+4


source


pppd

automatically calls the script in /etc/ppp/ip-up

on link up. In this script, $4

is the local IP address of the PPP link. (On some distributions /etc/ppp/ip-up

, the script call is set to /etc/ppp/ip-up.d

, it is $PPP_LOCAL

set to the IP address, so you can put the script there).



This way you don't have to manually call the script - just call the PPP link and it will be launched automatically. There's a corresponding /etc/ppp/ip-down

one that you can use to reverse the route when the link goes down.

+2


source







All Articles