Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

$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|improve this answer
    
Yes, it works. So $IP4_ADDRESS_0 is not a predefined variable like the $IFACE or $METHOD, right? –  platinor Jul 31 '13 at 8:37
    
@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. –  slm Jul 31 '13 at 8:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.