I'm trying to extract information from my '/etc/resolv.conf' file for a firewall script. The interface will be assigned IP and DNS info via DHCP, and to keep things fairly strict, I want to have the IP and DNS info used in my firewall script. Here is what I've done so far (if someone has a better solution, please don't hesitate to correct me!
):
Code:
ifconfig |grep eth0 -C 1|grep inet|cut -d ':' -f 2|cut -d ' ' -f 1 > IIP
cat /etc/resolv.conf | cut -d ' ' -f 2 > DNS
The first line returns my IP just fine. The second, however, creates 2 - 4 lines (whatever DNS entries have been assigned). How would I limit what lines I want? (ie, DNS1 = the first line, DNS2 = the second line, etc.).
The other thing is that this method saves the info to a file (due to the '>'). What if I just want a variable in the firewall script to be assigned the information?