I can't find any info regarding this in the man-pages. How would one go about only printing the gateway using traceroute?
Asked
Active
Viewed 1,143 times
3
-
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
-
1You 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
-
@dessert Yeah, grep would work. But the question eludes to there being a flag for traceroute to only print the gateway. Which has me confused since I can't see anything in the man-pages. – Lithicas Nov 28 '17 at 21:45
1 Answers
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.
Abhik Bose
- 2,090
- 2
- 15
- 30
-
1indeed, you beat me to it ; as an additional curiosity, the max limit is 64 hops. – Rui F Ribeiro Nov 28 '17 at 21:46
-
1Brilliant, thank you for your time! And thank you @RuiFRibeiro for you help too! – Lithicas Nov 28 '17 at 21:48
-
-
You can pipe the output with | awk '/2 / { print $2 }' to print only the gateway ip – charles Apr 17 '19 at 02:26