Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

Can we create bandwidth limits for all users?

I want to share internet through my Ubuntu Server. Is this possible or not?

share|improve this question

marked as duplicate by Sylvain Pineau, karel, Eric Carvalho, Luis Alvarado Jul 24 at 19:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I did investigate this over a year ago. I will need to research my notes. –  david6 Apr 28 at 8:05

1 Answer 1

Sharing Internet Connection is easy, and DpN has already provided a possible solution to that through a GUI. Alternatively, you can use iptables and masquerading to achieve the same, though it'll be without a GUI. More information can be had on http://www.tldp.org/HOWTO/IP-Masquerade-HOWTO/firewall-examples.html

Following is a sample script that you can run on the server. You can provide the gateway of this server to other machines so that they can access internet through this.

#!/bin/bash

echo -e "\n\nSETTING UP IPTABLES PROXY..."

INTIF="eth0"
EXTIF="eth1"
EXTIP="your.static.IP.address"

echo "Loading required stateful/NAT kernel modules..."

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc

echo "    Enabling IP forwarding..."
echo "1" > /proc/sys/net/ipv4/ip_forward

echo "    Loading proxy server rules..."

# Clearing any existing rules and setting default policy
iptables -P INPUT ACCEPT
iptables -F INPUT 
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT 
iptables -P FORWARD DROP
iptables -F FORWARD 
iptables -t nat -F

# FWD: Allow all connections OUT and only existing and related ones IN
iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

# Enabling SNAT (MASQUERADE) functionality on $EXTIF
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

echo -e "       Proxy server rule loading complete\n\n"

However, managing / limiting bandwidth (also called traffic shaping) is a different ball game. You would need to have some advanced knowledge of the tools to be used and what your needs would be. There are some external firwalls such as pfSense which help you manage it pretty well, but it'll require a different type of network setup.

share|improve this answer
    
"However, managing / limiting bandwidth (also called traffic shaping) is a different ball game." -- well, that is exactly what he asked for, so I'm not sure what the purpose is of the rest of your answer. –  bigbadonk420 Apr 28 at 8:53
    
Sorry, I didn't see the title. The second part of the question was about sharing internet connectivity through the server. –  Vivek Kapoor Apr 28 at 9:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.