{"id":9176,"date":"2021-08-13T11:19:52","date_gmt":"2021-08-13T11:19:52","guid":{"rendered":"https:\/\/linuxways.net\/?p=9176"},"modified":"2021-08-13T11:19:52","modified_gmt":"2021-08-13T11:19:52","slug":"route-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/route-command-in-linux\/","title":{"rendered":"Route Command in Linux"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Routing is a difficult technique in the networking world. In order to make your computers communicate with other devices on the network, you have to define the route for them.<\/p>\n<p>Thanks to the route command, the network administrators or Linux users can do this work in an easier way.<\/p>\n<p>Route command can be used to show and modify the network routing table in a Linux system.<\/p>\n<p>Below is the guide on how to use the route command in Linux.<\/p>\n<h2>Routing table<\/h2>\n<p>To show the current routing table, let\u2019s run the following command<\/p>\n<pre>$ route -n<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1436\" height=\"366\" class=\"wp-image-9177\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-189.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-189.png 1436w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-189-300x76.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-189-1024x261.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-189-768x196.png 768w\" sizes=\"auto, (max-width: 1436px) 100vw, 1436px\" \/><\/p>\n<p>Another way to describe more detail about which network interface of routes is running the command:<\/p>\n<pre>$ ip route show<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1390\" height=\"258\" class=\"wp-image-9178\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-190.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-190.png 1390w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-190-300x56.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-190-1024x190.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-190-768x143.png 768w\" sizes=\"auto, (max-width: 1390px) 100vw, 1390px\" \/><\/p>\n<h2>Add a new route<\/h2>\n<p>If your computer has more than one network interface and you want to add a new route, the computer will send traffic through that new gateway. You can use the route add command as below:<\/p>\n<pre>$ sudo route add -net &lt;NETWORK-ADDRESS&gt; gw &lt;GATEWAY&gt; &lt;NETWORK-INTERFACE&gt;<\/pre>\n<p>For example:<\/p>\n<pre>$ sudo route add -net 192.168.1.0\/24 gw 192.168.1.1 eth2<\/pre>\n<p>To add a new route to a host, run the following command:<\/p>\n<pre>$ sudo route add -host &lt;HOST-IP&gt; gw &lt;GATEWAY&gt;<\/pre>\n<p>For example:<\/p>\n<pre>$ sudo route add -host 172.19.11.75 gw 172.19.11.1<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1438\" height=\"472\" class=\"wp-image-9179\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-191.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-191.png 1438w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-191-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-191-1024x336.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-191-768x252.png 768w\" sizes=\"auto, (max-width: 1438px) 100vw, 1438px\" \/><\/p>\n<p>In the Flags column, there are some values that are difficult to understand. The following section is a quick explanation:<\/p>\n<p>U: up<\/p>\n<p>H: host<\/p>\n<p>G: gateway<\/p>\n<p>!: rejected route<\/p>\n<h2>Delete a route<\/h2>\n<p>If you no longer use a specific route and you want to delete it, you can simply run the following command:<\/p>\n<pre>$ sudo route del -net &lt;NETWORK-ADDRESS&gt; gw &lt;GATEWAY&gt; &lt;NETWORK-INTERFACE&gt;<\/pre>\n<p>For example:<\/p>\n<pre>$ sudo route del -net 192.168.1.0\/24 gw 192.168.1.1 eth2<\/pre>\n<p>To reject a route but you want to keep it on the routing table, run the command with the reject option.<\/p>\n<pre>$ sudo route add -host 172.19.11.75 reject<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1438\" height=\"472\" class=\"wp-image-9180\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-192.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-192.png 1438w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-192-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-192-1024x336.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-192-768x252.png 768w\" sizes=\"auto, (max-width: 1438px) 100vw, 1438px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>You have just read a tutorial about how to use the route command in a Linux system with examples.<\/p>\n<p>Thanks for reading. If you have any concerns, feel free to leave your comment and let me know.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction Routing is a difficult technique in the networking world. In order to make your computers communicate with other devices on the network, you have to define the&hellip;<\/p>","protected":false},"author":1,"featured_media":9276,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[476],"class_list":["post-9176","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-route-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=9176"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9176\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/9276"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=9176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=9176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=9176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}