Compartilhar Internet ou DHCP Server

Compartilhamento de Internet


1. Start by configuring the network card that interfaces to the other computers on you network:
# ifconfig ethX ip
where ethX is the network card and ip is your desired server ip address (Usually is used)

2. Then configure the NAT as follows:
# iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE
where ethX is the network card that the Internet is coming from
# echo 1 > /proc/sys/net/ipv4/ip_forward

3. Install dnsmasq and ipmasq using apt-get:
# apt-get install dnsmasq ipmasq

4. Restart dnsmasq:
# /etc/init.d/dnsmasq restart

5. Reconfigure ipmasq to start after networking has been started:
# dpkg-reconfigure ipmasq

6. Repeat steps 1 and 2.

7. Add the line "net.ipv4.ip_forward = 1" to /etc/sysctl.conf
# gedit /etc/sysctl.conf

8. Reboot. (Optional)

DHCP Server


sudo apt-get install dhcp3-server
Note: Don’t be alarmed if the startup fails; that’s because you haven’t configured it yet.

First, we need to tell the DHCP server to only run on eth1:
sudo gedit /etc/default/dhcp3-server

enter the following line save and exit file.
sudo gedit /etc/dhcp3/dhcpd.conf

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
#Máscara da rede
option subnet-mask;
#Broadcast que será utilizado na rede
option broadcast-address;
#Roteador da rede que neste caso será o próprio servidor DHCP
option routers;
#Servidor de domínio da rede (DNS) que também é o próprio servidor
option domain-name-servers;
#Nome do domínio da rede
option domain-name "casa.lan";
#Aqui mostra qual a rede que será utilizada no DHCP Server e o
#range de IPs que será utilizado para enviar para as máquinas da rede
subnet netmask {
option routers;

Configurar interface ETH1
cp /etc/network/interfaces /etc/network/interfaces.old
gedit /etc/network/interfaces

auto eth1
iface eth1 inet static

sudo /etc/init.d/networking restart 
/etc/init.d/dhcp3-server start