雲服務器多網卡配置實踐

環境概述:

系統環境:標準型S二、1核2G、1Mbps、Centos7.4 64位、騰訊雲、北京一區、VPC(私有網絡)shell

遠程鏈接工具:xshell5vim

目標:

爲服務器配置 2個網卡,每一個網卡配置2個內網ip、2個外網ip,共計4個外網ip、4個內網ipcentos

開始配置

在服務器建立完以後,會有一個彈性網卡--主網卡,以下方截圖所示:https://console.cloud.tencent.com/vpc/eni安全

1、爲主網卡再綁定一個外網ip、一個內網ip,以下方截圖

1)分配內網ip

2)綁定彈性公網ip;若是已有彈性公網ip,選擇「使用現有EIP綁定」;若是沒有,則選擇「新建EIP綁定」便可

3)已將一個彈性網卡綁定2個外網ip、2個內網ip以後的效果圖

4)遠程鏈接服務器,修改網卡配置文件

# 修改前先備份ifcfg-eth0
[root@VM_0_100_centos ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0{,.bak}

# 修改網卡配置文件
[root@VM_0_100_centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none                 # 不要設置dhcp
DEVICE=eth0

IPADDR0=10.0.0.100
NETMASK0=255.255.255.0

IPADDR1=10.0.0.101
NETMASK1=255.255.255.0

GATEWAY=10.0.0.1

NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PERSISTENT_DHCLIENT=yes

# 重啓網卡
[root@VM_0_100_centos ~]# systemctl restart network.service

# 查看配置成功後的效果
[root@VM_0_100_centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:8a:7a:64 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.101/24 brd 10.0.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever

5)驗證配置的外網IP是否可用

2、添加輔助網卡及配置

1)添加輔助網卡

2)綁定彈性公網ip

3)綁定雲主機

4)遠程鏈接服務器,修改網卡配置文件、關閉rp_filter校驗

# 複製ifcfg-eth0的配置爲ifcfg-eth1
[root@VM_0_100_centos ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth{0,1}

# 修改ifcfg-eh1網卡
[root@VM_0_100_centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none                    # 不要設置dhcp
DEVICE=eth1                       # 網卡設置名修改成eth1

IPADDR0=10.0.1.100
NETMASK0=255.255.255.0

IPADDR1=10.0.1.101
NETMASK1=255.255.255.0

GATEWAY=10.0.1.1                  # 網關 10.0.1.1

NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PERSISTENT_DHCLIENT=yes

# 關閉 rp_filter 校驗
[root@VM_0_100_centos ~]# vim /etc/sysctl.conf
# 找到第16行的rp_filter,註釋掉
#net.ipv4.conf.default.rp_filter = 1
# 在文件結尾加上以下4行
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0
net.ipv4.conf.eth1.rp_filter = 0

# 重啓網卡
[root@VM_0_100_centos ~]# systemctl restart network.service 

# 查看配置成功後的效果
[root@VM_0_100_centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:8a:7a:64 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.101/24 brd 10.0.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 20:90:6f:7c:98:c9 brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.100/24 brd 10.0.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet 10.0.1.101/24 brd 10.0.1.255 scope global secondary eth1
       valid_lft forever preferred_lft forever

5)驗證配置的外網IP是否可用

綁定安全組

到目前爲止已經配置成功,須要注意一點,若是服務器綁定了安全組,以前綁定的安全組不會自動綁定到輔助網卡上,須要**手動綁定安全組**:

參考文檔

雲服務器概述:https://cloud.tencent.com/document/product/213/495bash

彈性網卡幫助文檔:https://cloud.tencent.com/document/product/215/6513服務器

彈性網卡綁定和配置雲主機:https://cloud.tencent.com/document/product/576/18535網絡

安全組幫助文檔:https://cloud.tencent.com/document/product/213/18197#common工具

注意:

本博文僅供參考,讀者可根據本身的實際狀況,進行配置。oop

個人博客即將同步至騰訊雲+社區,邀請你們一同入駐:https://cloud.tencent.com/developer/support-plan?invite_code=2pkrzv40cneo8 spa

相關文章
相關標籤/搜索