LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-12-2010, 03:56 PM   #1
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Rep: Reputation: 15
Limiting Bandwidth Per IP in Ubuntu


Hi All,

You may have seen some other posts by me about my final year college project. Im implementing a web based network management website.

Iv got a lot of the functionality working at this stage but one part is allocating bandwidth.

Iv got an eircom 3mb broadband connection and I want to be able to split this between users. At the moment I only have my desktop and laptop on the network. Im looking for advice on how i can allocate bandwidth with iptables and/or the tc tool in ubuntu.

My website is on an ubuntu virtual machine and written in php. Whatever about running the iptables and tc commands from php I still need to figure out the actual commands i need to use in the first place.

Can anyone give me some advice on how i can do this? Thanks
 
Old 04-12-2010, 04:22 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
There is actually a guide I used for testing a setup using tc a while back but I had to change something in it, now I don't recall what I had to change but I did find the guide--

http://zedomax.com/blog/2008/09/25/l...-and-iproute2/

Give that a try and if it has an issue come back and we'll help you figure the issue once we know what it is.
 
Old 04-13-2010, 04:41 AM   #3
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Thanks rweaver i'll give this a go.
 
Old 04-13-2010, 04:37 PM   #4
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Im pretty confused with all this tc stuff. Not really understanding it.

I tried the following command.

tc qdisc add dev eth0 handle ffff: ingress

tc filter add dev eth0 parent ffff: protocol ip prio 50 u32 match ip src 192.168.1.0/24 police rate 1.0mbit burst 10k drop flowid :1

Now it all ran but i dont really get what it is doing. Is this limiting the incoming connection to 1mb?
 
Old 04-17-2010, 05:10 AM   #5
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rweaver View Post
There is actually a guide I used for testing a setup using tc a while back but I had to change something in it, now I don't recall what I had to change but I did find the guide--

http://zedomax.com/blog/2008/09/25/l...-and-iproute2/

Give that a try and if it has an issue come back and we'll help you figure the issue once we know what it is.
Hi rweaver,

This tutorial seems to assume you have linux set up as a router. My set up is ubuntu on a virtual machine with windows xp on the host machine. There is also a laptop on my network. These are connected to a netopia 2247 nwg ADSL router for internet access. I have a 3mb broadband connection.

I want to allocate this 3mb between say the windows xp host and the laptop. Is this possible from the ubuntu vm?

Sorry now if im asking stupid questions but im just really confused by all this stuff.
 
Old 04-18-2010, 09:35 AM   #6
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Yes it is possible, however it will be difficult without a basic understanding of the networking involved.
You will need to:
set two bridged network adapters for the guest OS (ubuntu) from your VM server software.
Then you will need to set up one of the interfaces to have an IP address in the range of your router
Setup the other interface to be in a separate network range
Set the two physical computers to use the same IP range as the second interface on the virtual machine with the virtual machine IP set as the default gateway
Then you need to setup the virtual machine as a router to route between the two networks
That might be confusing so I will try to give you a more specific example.

By setting the network interfaces in bridged mode from your VM server, we can pretend that the VM is a physically separate computer. And by setting the IP ranges to be different between the computers and the router we can make them have logical network separation too. The VM will join the two logically separated networks because it is the only device able to communicate with both the computers and the ADSL router.

Look at the diagram I have attached to get a better idea of what I mean.

If you need any further help implementing the above, you will need to post with more details about your current setup. Post IP addresses of all of your devices (including the ADSL router) and also the details of your VM software.
Attached Thumbnails
Click image for larger version

Name:	NetworkDiagram.jpg
Views:	101
Size:	28.4 KB
ID:	3372  
 
Old 04-18-2010, 01:28 PM   #7
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by SuperJediWombat! View Post
Yes it is possible, however it will be difficult without a basic understanding of the networking involved.
You will need to:
set two bridged network adapters for the guest OS (ubuntu) from your VM server software.
Then you will need to set up one of the interfaces to have an IP address in the range of your router
Setup the other interface to be in a separate network range
Set the two physical computers to use the same IP range as the second interface on the virtual machine with the virtual machine IP set as the default gateway
Then you need to setup the virtual machine as a router to route between the two networks
That might be confusing so I will try to give you a more specific example.

By setting the network interfaces in bridged mode from your VM server, we can pretend that the VM is a physically separate computer. And by setting the IP ranges to be different between the computers and the router we can make them have logical network separation too. The VM will join the two logically separated networks because it is the only device able to communicate with both the computers and the ADSL router.

Look at the diagram I have attached to get a better idea of what I mean.

If you need any further help implementing the above, you will need to post with more details about your current setup. Post IP addresses of all of your devices (including the ADSL router) and also the details of your VM software.
Thanks for the reply SuperJediWombat!.

Here is a list of the current ip addresses on my network.

ADSL Router (Netopia 2247-NWG Vgx): 192.168.1.254

Desktop: 192.168.1.2

Laptop: 192.168.1.15

My vm software is VMWare Workstation 6.5.

My vm is Ubuntu 9.10. I currently have 1 bridged network adapter on this virtual machine. Will I have to reinstall the virtual machine to add another network adapter?

Hopefully not.

I have my website on this vm.

Thanks again for your reply. You have given me a clearer picture of what I need to do.
 
Old 04-18-2010, 02:46 PM   #8
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Sorry I realise now I need to add another NIC to my system. I will do that first. Thanks
 
Old 04-18-2010, 07:40 PM   #9
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
You do not need a second physical NIC. You need to give your Virtual Machine a second NIC (you will not need to reboot it to do that.

The picture I drew is only a logical representation of the network. See the attached physical representation.
Attached Thumbnails
Click image for larger version

Name:	PysicalNetworkDiagram.jpg
Views:	67
Size:	42.8 KB
ID:	3375   Click image for larger version

Name:	LogicalNetworkDiagram.jpg
Views:	57
Size:	38.2 KB
ID:	3376  

Last edited by SuperJediWombat!; 04-18-2010 at 07:42 PM.
 
Old 04-19-2010, 04:38 AM   #10
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Thanks, so much for this advice. I will have a shot later when i get home at setting this up.

One other thing. My laptop connects wirelessly to the router for internet access.

Will this affect what i am trying to do?
 
Old 04-19-2010, 04:42 AM   #11
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Happy to help. No, wireless will not make a difference.

Last edited by SuperJediWombat!; 04-19-2010 at 04:46 AM.
 
Old 04-19-2010, 04:55 AM   #12
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Thanks again.

I may have more questions for you later.
 
Old 04-19-2010, 01:12 PM   #13
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by SuperJediWombat! View Post
Happy to help. No, wireless will not make a difference.
Well I have set up the network layout you outline above.

The next step is making linux perform as a router. Can you give me a guide on how to do this?
 
Old 04-19-2010, 07:22 PM   #14
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Sorry, I thought I allready had...

Code:
echo "1" >/proc/sys/net/ipv4/ip_forward
For ubuntu, add that to rc.local or something because it won't stay after a reboot.

/proc/sys/net/ipv4/ip_forward is a special file that tells the kernel what to do if it receives a packet that is addressed to another computer. If it is sent to '1' the kernel will look at the routing table, and work out what interface to send it out on.

You will also need to set up either a static route on the ADSL router, telling the router about the second network.
So open the web interface of your router, look for a page for entering 'static routes' and tell it that network '10.2.2.0/24' or '10.2.2.0 / 255.255.255.0' is on the gateway 10.1.1.250. If it wants a 'metric' or 'hops' just use '1'

The other option would be to setup NAT on your ubuntu box. This would mean that you wouldn't need to do the static route from your router, but it would slightly increase the overhead on your VM and might cause you some problems if you use any strange network protocols from your desktop/laptop.

If you want to enable NAT, run this command from your ubuntu VM

Code:
iptables -t nat -A POSTROUTING -o eth1 -s 10.2.2.0/24 -j MASQUERADE
Replace 'eth1'with whatever your external interface is (the one on the same IP range as your ADSL router)
And replace '10.2.2.0/24' with the IP range you have set for your Desktop/Laptop
 
Old 04-21-2010, 05:00 AM   #15
mossy464
Member
 
Registered: Jan 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by SuperJediWombat! View Post
Sorry, I thought I allready had...

Code:
echo "1" >/proc/sys/net/ipv4/ip_forward
For ubuntu, add that to rc.local or something because it won't stay after a reboot.

/proc/sys/net/ipv4/ip_forward is a special file that tells the kernel what to do if it receives a packet that is addressed to another computer. If it is sent to '1' the kernel will look at the routing table, and work out what interface to send it out on.

You will also need to set up either a static route on the ADSL router, telling the router about the second network.
So open the web interface of your router, look for a page for entering 'static routes' and tell it that network '10.2.2.0/24' or '10.2.2.0 / 255.255.255.0' is on the gateway 10.1.1.250. If it wants a 'metric' or 'hops' just use '1'

The other option would be to setup NAT on your ubuntu box. This would mean that you wouldn't need to do the static route from your router, but it would slightly increase the overhead on your VM and might cause you some problems if you use any strange network protocols from your desktop/laptop.

If you want to enable NAT, run this command from your ubuntu VM

Code:
iptables -t nat -A POSTROUTING -o eth1 -s 10.2.2.0/24 -j MASQUERADE
Replace 'eth1'with whatever your external interface is (the one on the same IP range as your ADSL router)
And replace '10.2.2.0/24' with the IP range you have set for your Desktop/Laptop
Hi mate.

Just a bit confused about configuring the static route on my router.

Im giving the router an ip address of 192.168.0.1.

The two windows machines are on the range of 192.168.1.0/24

I found the page to configure a static route on the router but not sure what address to put in.

See attached screenshot of router config.
Attached Thumbnails
Click image for larger version

Name:	staticroute.jpg
Views:	90
Size:	54.2 KB
ID:	3406  
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Limiting Bandwidth rajaguru14 Linux - Newbie 3 02-14-2009 01:35 PM
Bandwidth Limiting signature16 Linux - Software 4 05-21-2006 03:53 PM
limiting bandwidth Ammad Linux - General 1 10-06-2005 05:38 AM
Bandwidth limiting dunkyb Linux - Networking 3 09-17-2003 04:36 AM
Bandwidth Limiting boundless Linux - Networking 2 04-15-2003 02:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration