How to configure centos7 dual network card with static IP

  • 2020-05-14 05:54:17
  • OfStack

The problem of north network, south telecommunication is very let a person depressed 1, this also is a kind of characteristic of river crab society. To solve this problem, I have considered three options:

1, dual network CARDS, dual IP; Or single network card, double IP.

This is a low cost solution, but maintenance is difficult and slower than the last two.

2. BGP two-wire machine room.

The cost of BGP is higher than that of the first scheme, but there should be only so many BGP rooms in the country. There are more fake ones. Use this solution

No need to double the IP, one IP is OK.

3, CDN acceleration

The price of CDN is the highest. I bought the server of dell r410, which is in the machine room. The bandwidth is 160 yuan /m/ month. I talked with the account manager of chinacache face to face. At the beginning, the price was 400 yuan /m/ month. Later, I said that my friend recommended the price to be reduced to 200 yuan /m/ month. I have an QQ group of Linux operations and ask how much the CDN of chinacache is 1M per month. Some say over 100 yuan /m per month, some say over 900 yuan /m per month. It doesn't feel standard, so it is useless. Now I start a business with my friends and save as much as I can. So I choose the first plan. With that said, let's get down to business.

1. Server service arrangement

Server. I have prepared three machines of dell r410.

1, web server

2, MySQL server

3. File server

Each server has 2 network CARDS, eth1 for internal network, eth0 for external network, and both netcom and telecom use eth0, which I personally think is faster than 1 network card for netcom and 1 network card for telecom. On the switch set 2 vlan1 to go internal network, 1 to go external network, switch Settings are not here to say more.

2. Network configuration

1,cd /etc/sysconfig/network-scripts

2, the modified ifcfg - eth1


[root@localhost network-scripts]# cat ifcfg-eth1 
DEVICE="eth1" 
NM_CONTROLLED="yes" 
ONBOOT="yes" 
TYPE=Ethernet 
BOOTPROTO=none 
IPADDR=192.168.1.2 
PREFIX=24 
DEFROUTE=yes 
IPV4_FAILURE_FATAL=yes 
IPV6INIT=no 
NAME="System eth1" 
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 
HWADDR=78:2B:CB:57:28:E5 

3, modify ifcfg - eth0


[root@localhost network-scripts]# cat ifcfg-eth0 
DEVICE="eth0" 
NM_CONTROLLED="yes" 
ONBOOT="yes" 
TYPE=Ethernet 
BOOTPROTO=none 
IPADDR=222.121.121.121 
PREFIX=24 
GATEWAY=222.121.121.1 
NETMASK=255.255.255.128 
DEFROUTE=yes 
IPV4_FAILURE_FATAL=yes 
IPV6INIT=no 
NAME="System eth0" 
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 
HWADDR=78:2B:CB:57:28:E6 

4,cp ifcfg-eth0 ifcfg-eth0:0


[root@localhost network-scripts]# cat ifcfg-eth0:0 
DEVICE="eth0:0" 
NM_CONTROLLED="yes" 
ONBOOT="yes" 
TYPE=Ethernet 
BOOTPROTO=none 
IPADDR=112.121.121.121 
PREFIX=24 
NETMASK=255.255.255.0 
DEFROUTE=yes 
IPV4_FAILURE_FATAL=yes 
IPV6INIT=no 
NAME="System eth0" 
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 
HWADDR=78:2B:CB:57:28:E6 

5, restart the network/etc/init d/network restart

Here, the dual network card, dual IP is basically configured, but netcom and telecom are the gateway of the telecom, in this case, packet loss will be more serious. To solve this problem, there are two better ways, 1 is to add static route, 1 is to add policy route. The way I did it was with static routing.

3. Add static routing


route add -net 1.24.0.0 netmask 255.248.0.0 gw 60.12.105.145 dev eth0:0
route add -net 1.56.0.0 netmask 255.248.0.0 gw 60.12.105.145 dev eth0:0

The above is added by command, if it is a dual network card to add dev. Since there are many static routes, it is better to add from 1.

1,vim route.sh

2. Add route add to route.sh

3,chmod +x route.sh

4, start up echo "sh/path/route. sh" > > /etc/rc.local


Related articles: