{"id":219,"date":"2015-09-07T06:59:32","date_gmt":"2015-09-07T06:59:32","guid":{"rendered":"http:\/\/onlinelab.info\/?p=219"},"modified":"2015-09-07T06:59:32","modified_gmt":"2015-09-07T06:59:32","slug":"how-to-use-linux-as-router","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2015\/09\/07\/how-to-use-linux-as-router\/","title":{"rendered":"How to use Linux as router"},"content":{"rendered":"<h3>Linux as a Router<\/h3>\n<p>In this practical we are using three computers. One Linux system will be use for routing and reset two will remain in two different networks. First we will configure the system which is going to play the role of router.<\/p>\n<p>How to create virtual LAN card<\/p>\n<h3 class=\"boldo\">Configure server system<\/h3>\n<p>You need two LAN card for routing between two networks or you can create virtual LAN card instead of deploying them physically.<\/p>\n<p>To create virtual Ethernet card change directory to<strong> \/etc\/sysconfig\/network-scripts<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_cd_script_dir.jpg\" alt=\"change directory network script\" width=\"495\" height=\"178\" border=\"0\" title=\"\"><\/p>\n<p><strong>ifcfg-eth0<\/strong> is the necessary script file for Ethernet 0. Copy this file to the same folder to create new virtual LAN cards.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_cp_eth0_eth1.jpg\" alt=\"cp eth0 eth0.1\" width=\"517\" height=\"34\" border=\"0\" title=\"\"><\/p>\n<p>Now on this newly created virtual LAN card. It could be done by <strong>service network restart<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_service_net_restart.jpg\" alt=\"service network restart\" width=\"607\" height=\"115\" border=\"0\" title=\"\"><\/p>\n<p>Run <strong>setup<\/strong> command and select network configuration sub window from list<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_server_setup.jpg\" alt=\"setup \" width=\"340\" height=\"24\" border=\"0\" title=\"\"><\/p>\n<p>You have two LAN card here, select<strong> eth0<\/strong> from list to assign IP<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_server_select_eth0.jpg\" alt=\"select eh0\" width=\"640\" height=\"208\" border=\"0\" title=\"\"><\/p>\n<div class=\"custom\"><ins class=\"adsbygoogle\"><ins id=\"aswift_2_expand\"><ins id=\"aswift_2_anchor\"><\/ins><\/ins><\/ins><\/div>\n<p>This Ethernet card will be the default gateway of first network set its IP to <strong>192.168.1.254<\/strong> and click on ok<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_server_ip_setup.jpg\" alt=\"assign ip \" width=\"388\" height=\"257\" border=\"0\" title=\"\"><\/p>\n<p>Now select<strong> eth0.1<\/strong> ( This our virtual LAN card which we create in our last sections)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_server_select_eth1.jpg\" alt=\"select eth1\" width=\"637\" height=\"209\" border=\"0\" title=\"\"><\/p>\n<p>Set its IP to <strong>192.168.0.254<\/strong> This will be the default gateway of other network. Click on<strong> OK<\/strong> then <strong>quit<\/strong> and<strong> quit<\/strong> to come back on command prompt<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_server_ip_setup_eth1.jpg\" alt=\"assign ip eth1\" width=\"385\" height=\"257\" border=\"0\" title=\"\"><\/p>\n<p>IP forwarding can be enabled by editing in <strong>\/etc\/sysctl.conf<\/strong> file. open this file<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_vi_sysctl.jpg\" alt=\"vi \/etc\/sysctl.conf\" width=\"477\" height=\"25\" border=\"0\" title=\"\"><\/p>\n<p>Locate the <strong>net.ipv4. ip_forward = 0 tag<\/strong>. and replace the value <strong>0<\/strong> to <strong>1<\/strong>. This will enable IP forwarding to permanently . But this require a system reboot.<\/p>\n<div class=\"custom\"><ins class=\"adsbygoogle\"><ins id=\"aswift_3_expand\"><ins id=\"aswift_3_anchor\"><\/ins><\/ins><\/ins><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_edit_file_sysctl.jpg\" alt=\"change value sysctl.conf\" width=\"491\" height=\"214\" border=\"0\" title=\"\"><\/p>\n<p>If don&#8217;t want to restart the system you can tell running kernel directly by <strong>echo<\/strong> command and kernel will enable the IP forwarding<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_echo_command.jpg\" alt=\"echo command\" width=\"637\" height=\"38\" border=\"0\" title=\"\"><\/p>\n<p>now configure our client system. we are using two system one from each network to test the connectivity .<\/p>\n<p>Our first system is a Linux machine run <strong>setup<\/strong> command on it<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_setup_client.jpg\" alt=\"setup commands\" width=\"221\" height=\"18\" border=\"0\" title=\"\"><\/p>\n<p>assign its IP address to<strong> 192.168.0.1<\/strong> with a default gateway of<strong> 192.168.0.254<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_linx_cl_ipconfigratio.jpg\" alt=\"assign IP address\" width=\"389\" height=\"257\" border=\"0\" title=\"\"><\/p>\n<p>now restart the network service and check connectivity form its default gateway ( Server IP)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_linx_cl_ping.jpg\" alt=\"ping\" width=\"606\" height=\"228\" border=\"0\" title=\"\"><\/p>\n<p>Now go on our other host which we are using a window machine ( You can also use Linux host ) and set IP address to<strong> 192.168.1.1<\/strong> with a default gateway to<strong> 192.168.1.254<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_win_ipconfiguration.jpg\" alt=\"ip configurations\" width=\"337\" height=\"250\" border=\"0\" title=\"\"><\/p>\n<p>now open command prompt and test connectivity with default gateway<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_win_ping_self.jpg\" alt=\"ping commands\" width=\"470\" height=\"335\" border=\"0\" title=\"\"><\/p>\n<p>At this point you have completed all necessary step&#8217;s to enable routing its time to verify this<\/p>\n<div class=\"custom\"><ins class=\"adsbygoogle\"><ins id=\"aswift_4_expand\"><ins id=\"aswift_4_anchor\"><\/ins><\/ins><\/ins><\/div>\n<h3>Test from windows system<\/h3>\n<p><strong>ping<\/strong> the Linux host located on other network<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_win_ping_replay.jpg\" alt=\"ping replay\" width=\"465\" height=\"372\" border=\"0\" title=\"\"><\/p>\n<h3>Test from Linux system<\/h3>\n<p><strong>ping<\/strong> the Window host located on other network<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"padded s5_lazyload\" src=\"http:\/\/computernetworkingnotes.com\/images\/rhce_certification\/image\/ass21_linux_client_ping.jpg\" alt=\"ping replay\" width=\"652\" height=\"340\" border=\"0\" title=\"\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux as a Router In this practical we are using three computers. One Linux system will be use for routing and reset two will remain in two different networks. First we will configure the system&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}