• Linux
  • FreeBSD
  • Networking
  • Python
  • AWS
  • WebDev
  • About Us

How to find the IP and Gateway of an Interface in FreeBSD

Written by
FreeBSD Leave a Comment

Sometimes it is very important to grep only the IP address and the gateway of a specific interface especially if you are automating the network side of your server.

To grep the IP address from an interface : where re1 is my WAN interface

ifconfig re1 | grep "inet " | cut -d\  -f2

To grep the gateway :

netstat -r4n | grep re1 | grep -v 'link' | awk '{print $2}' | head -n1

© Copyright 2020.TechieNix. All Rights Reserved.