Static routing is the term used to refer to the manual method used to set up routing. An administrator enters routes into the router using configuration commands. This method has the advantage of being predictable, and simple to set up. It is easy to manage in small networks but does not scale well.

Advantages of Static Routes

  • Easy to configure
  • No routing protocol overhead

Disadvantages of Static Routes

  • Network changes require manual reconfiguration
  • Network outages cannot be automatically routed around
  • Does not scale well in large networks.

Add a Static route using "route" command

route add [-net|-host] <IP/Net> netmask <Mask> gw <Gateway IP> dev <Int>X

Example

route add -net 10.10.10.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
route add -host 10.10.1.1 netmask 255.255.255.0 gw 192.168.1.1 dev eth0

This adds the route immediatly to the Kernel IP routing table. To confirm the route has been successfully, simply type the "route" command with no arguements:

route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.254 * 255.255.255.0 U 0 0 0 eth0
localnet * 255.255.255.0 U 0 0 0 eth0
10.10.10.0 * 255.255.255.0 U 0 0 0 eth0
10.10.1.1 * 255.255.255.0 U 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0

Use

netstat -rn

to print the Kernel IP Routing table.

To keep the Static Route persistent or you want to add the route entries to the network script files (not using the route command) then all you need to do is to edit the file

/etc/network/interfaces

and the static routes in the following format:

up route add [-net|-host] <host/net>/<mask> gw <host/IP> dev <Interface>

Example

up route add -net 172.20.11.0/16 gw 172.20.10.254 dev eth1

And the file will like the following

sudo cat /etc/network/interfaces

The output should show something like this

sudo cat /etc/network/interfaces

The output should show something like this

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0 eth1

iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
# dns-* options are implemented by the resolvconf package, if installed

iface eth1 inet static
address 172.20.10.1
netmask 255.255.255.0
broadcast 172.20.10.255
gateway 172.20.10.254

# static route
up route add -net 172.20.11.0/16 gw 172.20.10.254 dev eth1

The above has 2 Ethernet interfaces and the static route is added to the interface eth1.

For the change to /etc/network/interface to take effect. please restart the "networking" service as follows:

sudo /etc/init.d/networking restart

NOTE: If you added the route already using the "route" then there is no need to restart the networking service because, the next time server is restarted this takes effect.

Source page:http://www.ubuntugeek.com/howto-add-permanent-static-routes-in-ubuntu.html

Howto add permanent static routes in Ubuntu的更多相关文章

  1. How-To: add EPEL repository to Centos 6.x is Easy!

    How-To: add EPEL repository to Centos 6.x is Easy! | ITek Blog How-To: add EPEL repository to Centos ...

  2. Ubuntu 添加删除用户 How to Add and Delete Users on Ubuntu 16.04

      Introduction One of the most basic tasks that you should know how to do on a fresh Linux server is ...

  3. Add a system call on Ubuntu 13.04(x64) with x86_64

    We added a system call to modify idt table, then programed it in modify_idt.c 1. Put our modify_idt. ...

  4. 给ubuntu设置静态ip —— How to set static IP Address in Ubuntu Server 16.04

    原文: http://www.configserverfirewall.com/ubuntu-linux/ubuntu-set-static-ip-address/ ----------------- ...

  5. HOWTO install Oracle 11g on Ubuntu Linux 12.04 (Precise Pangolin) 64bits

    安装了Ubuntu 12.04 64bit, 想在上面安装Oracle 11gr2,网上找了好多文档都没成功,最后完全参考了MordicusEtCubitus的文章. 成功安装的关键点:install ...

  6. ubuntu下在apache部署python站点

    ubuntu下在apache部署python站点 我的是ubuntu14 32为的虚拟机,默认安装的python为3.4 环境:apache + mysql + django + python3 软件 ...

  7. Ubuntu & Docker & Consul & Fabio & ASP.NET Core 2.0 微服务跨平台实践

    相关博文: Ubuntu 简单安装 Docker Mac OS.Ubuntu 安装及使用 Consul Consul 服务注册与服务发现 Fabio 安装和简单使用 阅读目录: Docker 运行 C ...

  8. Ubuntu django+nginx 搭建python web服务器文件日志

    uwsgi 配置文件 [uwsgi] http-socket = 127.0.0.1:8080 # 项目目录 chdir=/home/ubuntu/mkweb # 指定项目的application m ...

  9. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(五):测试项目

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

随机推荐

  1. CommonJS规范(转)

    概述 CommonJS是服务器端模块的规范,Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.加载模块使用require方法,该方法读取一个文件并执行,最后返回文件 ...

  2. [转]无IDE时编译和运行Java

    本文由 ImportNew - Grey 翻译自 dzone.欢迎加入Java小组.转载请参见文章末尾的要求. 最近 Java subreddit 出现了一篇”在没有IDE的情况下编译Java包” 的 ...

  3. charCodeAt 和 fromCharCode

    1.charCodeAt() 定义和用法 charCodeAt() 方法可返回指定位置的字符的 Unicode 编码.这个返回值是 0 - 65535 之间的整数. 方法 charCodeAt() 与 ...

  4. mysql 无法启动1067

    关键字:mysql无法启动办事,mysql卡死,InnoDB"" registration as a STORAGE ENGINE failed.Unknown/unsupport ...

  5. MONGODB 查询

    1,mongoDB 取模运算:db.person.find({index:{$mod:[5,1]}})db.person.find({index:{$not:{$mod:[5,1]}}})2,name ...

  6. TDBGridEh的 搜索面板 TDBGridSearchPanel

    TCustomDBGridEh.Create FSearchPanelControl := TDBGridSearchPanelControlEh.Create(Self); //这里,创建的构造函数 ...

  7. Sublime Text 3 插件安装

    1.安装 Package Control 组件 sublime菜单栏->view->show console: 输入以下命令回车: import urllib.request,os; pf ...

  8. 分布式一致性原理—CAP

    背景 随着分布式事务的出现,传统的单机事务模型(ACID)已经无法胜任,尤其是对于一个高访问量.高并发的互联网分布式系统来说. 如果我们要求严格一致性,很可能就需要牺牲掉系统的可用性,反之亦然.但两者 ...

  9. 【转】Centos系统文件与用户权限分配详解ftp,nginx,php

    linux系统中权限是非常完善的一个功能了,我们如果设置不正确文件就无法使用了,像我们以一般情况需要把文件权限设置为777或644了,对于用户权 限就更加了,像素ftp,nginx,php这些我们都可 ...

  10. Google 宣布支持中文邮箱地址

    Gmail 宣布,即日起开始支持非拉丁字符邮箱地址.也就是说,我们可以在 Gmail 中针对中文邮箱地址发送和接收邮件了. 全世界母语是拉丁字母语言的人类不超过全人类总数的一半,母语是英语的人数更少. ...