AWS雲EC2 RHEL7 新增網路介面與路由調整

2022-08-05 01:03:09 字數 4293 閱讀 5257

bootproto=dhcp

device=eth1 #需要修改成eth1

hwaddr=0a:9e:bc:8a:6a:c0 #修改成新的mac位址

onboot=yes

type=ethernet

userctl=no

配置70檔案:

vim /etc/udev/rules.d/70-persistent-net.rules

subsystem"net", action"add", drivers"?*", attr"0a:47:43:38:60:58", name="eth0"

subsystem"net", action"add", drivers"?*", attr"0a:9e:bc:8a:6a:c0", name="eth1" #增加一行

注意,這裡還沒有重啟網路,故不會發生預設路由的變化.

記住,rhel7一定要配置真實的mac位址(不能自定義),否則極有可能造成系統起不來,報網路故障.

確認和調整路由

因新繫結了網路介面(以及該網路介面對應的內網ip),重啟網路服務的話,路由極有可能發生變化.

檢視當前路由:

route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default gateway 0.0.0.0 ug 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

這裡新增了10.0.1.23的介面,重啟後,預設路由很可能會變掉(測試的時候,確實變了,導致外網無法登陸ec2).

在未調整預設路由的情況下,重啟ec2後,路由表會變成:

route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default gateway 0.0.0.0 ug 0 0 0 eth1

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth1

預設理由隨機的給了eth1了,這個可不是希望看到的.

路由調整

臨時策略,新增預設路由

route add default gw 10.0.1.1 dev eth0

route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default gateway 0.0.0.0 ug 0 0 0 eth0 #預設路由重複了,這條生效

default gateway 0.0.0.0 ug 0 0 0 eth1 #預設路由重複了,這條未生效

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth1

將多出來的那個預設路由刪除

route del default gw 0.0.0.0 dev eth1

route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default gateway 0.0.0.0 ug 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth1

永久路由(新增1個檔案)

注:測試發現最終有效檔案是/etc/sysconfig/network-scripts/eth0.route

調整靜態路由對應的相關配置檔案(這裡都測試了,都不生效,測試時間20180625,版本rhel7.5,原因應該是2個網絡卡ip是同乙個位址段的,閘道器位址是一樣的)

/etc/sysconfig/network新增到末尾,全域性生效的.gateway=gw-ip或者gateway=gw-dev

/etc/sysconfig/network-scripts/ifcfg-eth0 #新增如下內容 gateway=x.x.x.x

/etc/sysconfig/network-scripts/eth0.route新增如下:(此檔案是通過同路徑下的那些網絡卡啟動指令碼發現的)

route add -net 10.0.1.0/24 dev eth0

route add default gw 10.0.1.1 dev eth0 #/var/log/messages會報錯siocaddrt: file exists(該路由已存在),所以才看不到預設路由走eth0.但第一條理由在路由表裡出現了.

路由表如下:

route

kernel ip routing table

destination gateway genmask flags metric ref use iface

default gateway 0.0.0.0 ug 0 0 0 eth1

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0

10.0.1.0 0.0.0.0 255.255.255.0 u 0 0 0 eth1

eth0.route測試通過.在rhel7中,如果修改為route-eth0(網上都說這種方法),/var/log/messages會報錯:

jun 25 20:47:59 ip-10-0-1-7 network: error: inet prefix is expected rather than "route".

jun 25 20:47:59 ip-10-0-1-7 network: error: inet prefix is expected rather than "route".

這裡應該是格式錯誤的意思,可以嘗試寫成如下2種格式再試試:

route-eth0檔案內容,

1):192.168.0.0/24 via 10.201.106.2

2):address0=192.168.20.0

netmask0=255.255.255.0

gateway0=10.201.106.2

address1=192.168.30.0

netmask1=255.255.255.0

gateway1=10.201.106.2

不過需要兩個網絡卡屬於不同的網段才能測試.

不推薦:

可以修改/etc/rc.local檔案(rhel7預設此檔案無執行許可權,需要更改為755).在rhel7之後,該檔案與其他服務啟動並行執行(systemd).

route add default gw 10.0.1.1 dev eth0

route del default gw 0.0.0.0 dev eth1

此方式在執行systemctl restart network.service後,eth1又會變成預設閘道器路由.不是很好的方式.

AWS的EC2例項建立

在不使用aws嚮導的情況下建立乙個ec2例項 0x01 設定vpc 建立vpc 建立閘道器 建立路由表 劃分子網 檢查配置是否到新的vpc中 1.建立vpc cidr classless inter domain routing無類域間路由 改進了傳統的ipv4位址分類。傳統的ip分類將ip位址直接...

AWS系列 EC2例項映象選擇

開啟ec2控制台,點選啟動例項,選擇aws marketplace centos.org說明為centos官網映象 如下圖,這種映象是收費的映象 ubuntu映象 使用centos redhat ubuntu amazon linux windows server 在aws marketplace ...

AWS系列 EC2預設限制說明

amazon ec2 提供您可以使用的不同資源,例如例項和卷。在您建立 aws 賬戶時,aws 會針對每個區域中的這些資源設定限制。此頁面列出您在 亞太區域 東京 中的 ec2 服務限制。開啟如下圖,所選控制項 如下圖,一些常見的限制,你們可以拉到下面去看那些有限制,如果需要提高限制的話。你們就要在...