FreeBSD Set a Default Route / Gateway

來源:互聯網
上載者:User

標籤:des   blog   http   ar   io   os   sp   for   strong   

FreeBSD Set a Default Route / Gateway

by NIXCRAFT on JANUARY 13, 2008 · 7 COMMENTS· LAST UPDATED OCTOBER 31, 2008

in FREEBSD, NETWORKING, TROUBLESHOOTING

Q. How do I modify or set a default route for my FreeBSD server? How do I make default route configuration persistent?

A. The route command is used under FreeBSD to manually manipulate the network routing tables. It provides six commands:
=> add : Add a route.

=> flush :Remove all routes.

=> delete : Delete a specific route.

=> change : Change aspects of a route (such as its gateway).

=> get : Lookup and display the route for a destination.

=> monitor : Continuously report any changes to the routing information base, routing lookup misses, or suspected network partitionings.

Task: View / Display FreeBSD Routing Table

Use netstat command with -r option:
$ netstat -r
$ netstat -rn

Output:

Routing tablesInternet:Destination        Gateway            Flags    Refs      Use  Netif Expiredefault            61.221.xx.yy       UGS         0      247    em110                 10.10.110.5        UGS         0       50    em010.10.110/26       link#1             UC          0        0    em010.10.110.5        00:1b:0d:e6:58:40  UHLW        2        0    em0   114561.221.xx.yy/29    link#2             UC          0        0    em161.221.xx.yy       00:1b:0d:e6:57:c0  UHLW        2        0    em1   105561.221.xx/24       link#2             UC          0        0    em1127.0.0.1          127.0.0.1          UH          0        0    lo0

The first two line displays default routes.

Task: FreeBSD Set a default route

All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway:
# route add default 192.168.1.254

How do I save routing information to a configuration file?

If you reboot FreeBSD box, the routing configuration will be lost i.e. the routing information will not persist. You need to edit /etc/rc.conf file to set defaultroute:
# vi /etc/rc.conf
Set default route by editing defaultrouter variable:
defaultrouter="192.168.1.254"
Save and close the file.

Task: Start and Stop FreeBSD Configured Interfaces

To apply changes to a configuration file, you need to stop and restart the corresponding FreeBSD networking interface. The following command will also update routing information:
# /etc/rc.d/netif restart
# /etc/rc.d/routing stop
# /etc/rc.d/routing start

來源: <http://www.cyberciti.biz/faq/freebsd-setup-default-routing-with-route-command/> 



來自為知筆記(Wiz)

FreeBSD Set a Default Route / Gateway

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.