Linux服務器雙網卡雙IP和單網卡雙IP配置方法(Debian/Ubuntu)


一、雙網卡雙IP。

eth0為電信,eth1為聯通。

# cd /etc/network/

#vi interfaces

# 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

 

auto eth0

iface eth0 inet static

address 114.80.0.4

netmask 255.255.255.128

gateway 114.80.0.3

 

auto eth1

iface eth1 inet static

address 112.65.0.2

netmask 255.255.255.0

######################################################

然后做策略路由(這里的策略路由文件由機房提供)。

二、單網卡雙IP。

# This file describes the network interfaces availableon your system

# and how to activate them. For more information, see interfaces(5).

#/etc/network/interfaces

 

# The loopback network interface

auto lo

iface lo inet loopback

 

auto eth0

iface eth0 inet static

address 192.168.1.116

netmask 255.255.255.0

gateway 192.168.1.2

broadcast 192.168.1.255

# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 61.134.1.4

 

auto eth0:1

iface eth0:1 inet static

address 192.168.1.135

netmask 255.255.255.0

gateway 192.168.1.2

broadcast  192.168.1.255

######################################################

然后做策略路由。

三、配置策略路由。

Ubuntu、debian的開機自啟動服務和RedHat、CentOS都不一樣,Ubuntu、debian需把寫好的腳本放到指定目錄! 

步驟如下:

把路由列表文件static-routes放置在/etc/init.d目錄中,賦予可執行權限,然后執行一下。

cd /etc/init.d

chmod +x /etc/init.d/static-routes

./static-routes.sh     #帶路由信息的shell腳本

update-rc.d static-routes  start 20 2 3 4 5 . stop 01 0 1 6 .

#表示在2、3、4、5這五個運行級別中,由小到大,第二十個運行static-routes

#在0、1、6三個級別中,第一個關閉static-routes

#注意它有2個點號,效果等於下面方法:

update-rc.d static-routes defaults

(使用update-rc.d 命令來控制具體的加入,有點類似於RedHat下的chkconfig命令)

sudo apt-get install sysv-rc-conf     

(一個強大的服務管理程序,有點類似RedHat下ntsysv與setup)

使用sysv-rc-conf檢查static-routes是否添加並啟動

清除開機啟動設置執行下面的命令:

update-rc.d -f static-routes remove

完成后重啟服務器,測試路由信息是否失效。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM