大网数据广告活动
服务器运维问答

How to bind all traffic to a specific IP on a specific NIC?

· 52CE 我爱测

I'll have to setup a few servers with each 2 network interfaces. Since I am new to server configuration and networks, I am currently trying to simulate everything on virtual machines. Each server will have 2 NICs, eth0 and eth1. …

问题原文

原帖链接 · antesoles · CC BY-SA 3.0

I'll have to setup a few servers with each 2 network interfaces. Since I am new to server configuration and networks, I am currently trying to simulate everything on virtual machines.

Each server will have 2 NICs, eth0 and eth1. All eth0 will be connected to a gateway and through that to the internet. All eth1 will be connected to a private switch. eth0 should be used for all external traffic (internet). All traffic between the servers should go only through each server's eth1 (without using the gateway).

If I understand everything right, I have to define (static) routes. What I don't really get are the netmasks and if I have to setup a route for every server or if I have to define one route with a specific netmask to cover all the eth1 IP addresses.

Let's say:

Server A eth0 has the IP 192.168.1.91 (will be later internet).
Server A eth1 has the IP 192.168.1.92 (local network).

Server B eth0 has the IP 192.168.1.93 (will be later internet).
Server B eth1 has the IP 192.168.1.94 (local network).

Server C eth0 has the IP 192.168.1.95 (will be later internet).
Server C eth1 has the IP 192.168.1.96 (local network).

I've defined a route now on Server A:

route add -net 192.168.1.94 netmask 255.255.255.255 dev eth1
route add -net 192.168.1.96 netmask 255.255.255.255 dev eth1

ip route get 192.168.1.94 results in

192.168.1.94 dev eth1  src 192.168.1.91

ip route get 192.168.1.96 results in

192.168.1.96 dev eth1  src 192.168.1.91

If I understand it right, then packets to 192.168.1.94 (and 96) will now be sent through eth1. But why is the source IP 192.168.1.91, even if this is eth0 and eth1 would be 192.168.1.92? Is there any possibility to to see on Server B, from each IP on Server A a request came? Let's say I make on Server A something like ping 192.168.1.93, can I check then on Server B from which IP that ping request came?

已采纳解答

原帖链接 · iwaseatenbyagrue · CC BY-SA 3.0

You should be able to get away with just a default route.

As explained by @RonMaupin, your private network requires no routing, it is layer 2, so hosts can 'find' one another. You do though need to use the private IPs (or hostnames) in any configuration where this matters.

For your internet NICs, you would configure their IPs, and set your system's default route to whatever your internet gateway is.

How exactly you do that depends on what your using, but on CentOS/RedHat/Fedora, assuming your internet gateway to have an IP of 10.0.0.1, I would edit /etc/sysconfig/network to add:

GATEWAY=10.0.0.1

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。