Environment variable for ip address

7,824

$IP4_ADDRESS_0 is a variable, so it's likely not set. You can see it's value with this command:

$ echo "$IP4_ADDRESS_0"

If it's blank you'll see this:

$ echo "$IP4_ADDRESS_0"

$

You could use this command instead:

$ ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
192.168.1.27
Share:
7,824

Related videos on Youtube

platinor
Author by

platinor

Updated on September 18, 2022

Comments

  • platinor
    platinor over 1 year

    I see somewhere people use:

    IF_ADDRESS="$(echo "$IP4_ADDRESS_0" | cut -d'/' -f1)"
    

    to get the IP address in a network configuration script. In my system, I create a script under the directory /etc/network/if-up.d/ and test with:

    echo "$IP4_ADDRESS_0" >> /tmp/test.log
    

    but get nothing with this variable. What's wrong?

    My /etc/network/interfaces is like this:

    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
    

    My final purpose is to set up the IP routing policy with a script like this.

  • platinor
    platinor almost 11 years
    Yes, it works. So $IP4_ADDRESS_0 is not a predefined variable like the $IFACE or $METHOD, right?
  • slm
    slm almost 11 years
    @platinor - I don't think so. If you use the command grep IP4 /etc/network/if-up.d/* you don't find any examples of it being used there.
  • Kusalananda
    Kusalananda almost 6 years
    The variable probably comes from some kind of dispatcher script relating to something called "NetworkManager" on Linux. I'm not a Linux guy, but that's what came up when searching.