我使用 Ubuntu 14.04 32 位
我有以下问题,我必须共享互联网: 1 个互联网服务器(eth1) 1 个使用其他网卡转发互联网(这是需要配置的机器 - eth2) Pcs 客户。
互联网通过一根网线连到服务器,另一张网卡连到为微客户端分配的交换机。
问题是:怎样获得一张可以上网的网卡并分配另一张呢?
先谢谢了。
请查看我的系统日志
May 7 10:40:37 asterisk dhcpd: options subnet-mask
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 6: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options broadcast-address
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 7: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options routers
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 8: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options domain-name-servers
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 9: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options domain-name
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: Configuration file errors encountered -- exiting
May 7 10:40:37 asterisk dhcpd: Internet Systems Consortium DHCP Server 4.2.2
May 7 10:40:37 asterisk dhcpd: Copyright 2004-2011 Internet Systems Consortium.
May 7 10:40:37 asterisk dhcpd: All rights reserved.
May 7 10:40:37 asterisk dhcpd: For info, please visit https://www.isc.org/software/dhcp/
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 5: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options subnet-mask
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 6: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options broadcast-address
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 7: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options routers
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 8: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options domain-name-servers
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: /etc/dhcp/dhcpd.conf line 9: semicolon expected.
May 7 10:40:37 asterisk dhcpd: options domain-name
May 7 10:40:37 asterisk dhcpd: ^
May 7 10:40:37 asterisk dhcpd: Configuration file errors encountered -- exiting
May 7 10:40:49 asterisk dhcpd: Wrote 0 leases to leases file.
May 7 10:40:49 asterisk dhcpd:
May 7 10:40:49 asterisk dhcpd: No subnet declaration for eth2 (no IPv4 addresses).
May 7 10:40:49 asterisk dhcpd: ** Ignoring requests on eth2. If this is not what
May 7 10:40:49 asterisk dhcpd: you want, please write a subnet declaration
May 7 10:40:49 asterisk dhcpd: in your dhcpd.conf file for the network segment
May 7 10:40:49 asterisk dhcpd: to which interface eth2 is attached. **
May 7 10:40:49 asterisk dhcpd:
May 7 10:40:49 asterisk dhcpd:
May 7 10:40:49 asterisk dhcpd: Not configured to listen on any interfaces!
答案1
首先要启用 IP 转发。可以使用
echo "1" > /proc/sys/net/ipv4/ip_forward
然后,我们将添加一条规则,告诉转发流量
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
最后,我们要求 IPtables 进行伪装
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
编辑1
安装
sudo apt-get install isc-dhcp-server
配置
sudo nano -w /etc/dhcp/dhcpd.conf
# Sample /etc/dhcpd.conf
# (add your comments here)
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name "mydomain.example";
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
range 192.168.1.150 192.168.1.200;
}
重启服务
sudo service isc-dhcp-server restart