3

I can't find any info regarding this in the man-pages. How would one go about only printing the gateway using traceroute?

  • would you clarify the question? it is not entirely clear what your need is. Maybe an example? – Rui F Ribeiro Nov 28 '17 at 21:30
  • @RuiFRibeiro Basically I'm looking for a way to use traceroute to only print one line. That line being the one containing the gateway information, nothing else. – Lithicas Nov 28 '17 at 21:33
  • anything against netstat -nr? I think what you want with traceroute can be done, will check it out and will come back. – Rui F Ribeiro Nov 28 '17 at 21:35
  • @RuiFRibeiro I appreciate your help. Nothing against netstat -nr. It's only that it's a school assignment that requires me to use traceroute. I've read the man-pages but haven't found a flag that does what I want, apparently it is possible though. – Lithicas Nov 28 '17 at 21:37
  • 1
    You should read about e.g. grep, sed and awk and how they can be used to cut out lines from traceroute's output. – dessert Nov 28 '17 at 21:39
4

With traceroute you've to enter maximum hop as 1 using m1 option as follows.

traceroute -m1 google.com

According to basic rules of computer network Gateway and host must be connected to same NIC of router. Otherwise Data Link Layer will unable to deliver packets from hosts to Gateway. So it's hop should be 1.

So by setting maximum hop as one and tracing any host will prit Gateway only.

  • 1
    indeed, you beat me to it ; as an additional curiosity, the max limit is 64 hops. – Rui F Ribeiro Nov 28 '17 at 21:46
  • 1
    Brilliant, thank you for your time! And thank you @RuiFRibeiro for you help too! – Lithicas Nov 28 '17 at 21:48
  • Really good question.. Liked it – Abhik Bose Nov 28 '17 at 21:54
  • You can pipe the output with | awk '/2 / { print $2 }' to print only the gateway ip – João José Apr 17 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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