LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-22-2016, 09:18 AM   #1
Bashed
Member
 
Registered: Jul 2015
Posts: 133

Rep: Reputation: Disabled
How do I bind a bunch of /24 subnets (secondary) in one shot in Ubuntu 14?


I need to bind a bunch of /24 IPv4 subnets as secondary. The primary /29 is already set during the installation of Ubuntu 14x. How do I bind the remainder /24 subnets in one shot instead of individual single IPs one at a time?

I tried this method by adding the below line in /etc/network/interfaces but it didn't work?

Quote:
up route add [-net|-host] <host/net>/<mask> gw <host/IP> dev <Interface>

root@server:~# /etc/init.d/networking restart
root@server:~#
I also tried this method too (below example, but did actual IPs and em1)

Quote:
for i in {1..128}; do echo iface eth1:$i inet static >> /etc/network/interfaces; echo address 192.168.0.$i >> /etc/network/interfaces; echo netmask 255.255.255.0 >> /etc/network/interfaces; echo auto eth1:$i >> /etc/network/interfaces; done
Quote:
root@server:~# service networking restart
stop: Job failed while stopping
start: Job is already running: networking
root@server:~# ifdown em1 && sudo ifup em1
IPs still don't ping however. They're 100% routed correctly on the Cisco switch though.

Last edited by Bashed; 11-22-2016 at 09:43 AM.
 
Old 11-22-2016, 11:00 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
The bigger question is why do you want to do this? There has got to be a better way then building 128 sub interfaces if you just explain what it is your are trying to accomplish.
 
Old 11-22-2016, 11:05 AM   #3
Bashed
Member
 
Registered: Jul 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
What do you mean why? I need it for a specific use for one of my clients who needs a handful of /24 subnets on the server. That's why.

My question is HOW to do this in one shot instead of individual single IPs at a time.
 
Old 11-22-2016, 12:20 PM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Understand, there is no simpler way to do this.

Code:
for i in {RANGE}
        do ip addr add NETWORK.$i/MASK dev INTERFACE
done

ip addr show
This simple script makes all the ip addreeses you add as a secondary to the primary IP Address.
Make sure you change the RED Highlighted items to match what you need.
 
Old 11-22-2016, 12:25 PM   #5
Bashed
Member
 
Registered: Jul 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by lazydog View Post
Understand, there is no simpler way to do this.

Code:
for i in {RANGE}
        do ip addr add NETWORK.$i/MASK dev INTERFACE
done

ip addr show
This simple script makes all the ip addreeses you add as a secondary to the primary IP Address.
Make sure you change the RED Highlighted items to match what you need.

Thanks, but the problem with this method that I already posted and tried, is that doing the next following /24 subnets ends up starting with the same em1:1 - 254 numbering. Plus, even initially the IPs were not pinging anyway.
 
Old 11-22-2016, 01:01 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Bashed View Post
Thanks, but the problem with this method that I already posted and tried, is that doing the next following /24 subnets ends up starting with the same em1:1 - 254 numbering.
Nope. This sets up all the IP Address as secondary IP on the first interface. No sub-interfaces required.

Quote:
Plus, even initially the IPs were not pinging anyway.
Can you ping them from the server itself? You should be able to, if not then there is a problem on the server itself.

OK now you need to ensure that the IP Addresses you want to use are on the network that is directly connected to this system. For example if you are on network 192.168.1.x/24 but you want to use 192.168.0.x/24 you are going to have to get the network team to ensure that that ip address range is directed to your system. In this case you will most likely have to setup TRUNKing on the switch and the system to ensure that both ranges of IP Addresses will reach the system. Or if they run consecutively a simple change of the network mask could fix this also. Again you would have to talk with your networking team to get this all sorted out.
 
Old 11-22-2016, 01:19 PM   #7
Bashed
Member
 
Registered: Jul 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
I might be confused here, but this is what I've done.

nano addips.sh

Add:

Code:
for i in {2..254}
        do ip addr add xxx.xxx.3.$i/24 dev em1
done

ip addr show
chmod +x addips.sh
sh addips.sh

Output something like this...

Code:
    inet xxx.xxx.3.232/24 scope global secondary em1
       valid_lft forever preferred_lft forever
    inet xxx.xxx.3.233/24 scope global secondary em1
       valid_lft forever preferred_lft forever
    inet xxx.xxx.3.234/24 scope global secondary em1
       valid_lft forever preferred_lft forever
    inet xxx.xxx.3.235/24 scope global secondary em1
       valid_lft forever preferred_lft forever
    inet xxx.xxx.3.236/24 scope global secondary em1
       valid_lft forever preferred_lft forever
They ping! (Thank you)

Now, my question is can I do all 20 x /24 in that single script? Would I just copy/paste the above and simply modify the portions? Also, this isn't permanent because I rebooted the server, and the results were gone. How can I set them to be permanent?

Last edited by Bashed; 11-22-2016 at 01:45 PM.
 
Old 11-22-2016, 01:27 PM   #8
Bashed
Member
 
Registered: Jul 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
I actually tried this script, didn't work on the remaining 19 x 24s, only first on the list.

Code:
for i in {2..254}
        do ip addr add xxx.xxx.3.$i/24 dev em1
done		
for i in {2..254}
        do ip addr add xxx.xxx.58.$i/24 dev em1
done		
for i in {2..254}
        do ip addr add xxx.xxx.65.$i/24 dev em1
done		
for i in {2..254}
        do ip addr add xxx.xxx.80.$i/24 dev em1
done		
for i in {2..254}
        do ip addr add xxx.xxx.90.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.21.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.31.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.30.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.40.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.50.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.60.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.70.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.81.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.1.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.6.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.16.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.17.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.29.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.34.$i/24 dev em1
done		
for i in {2..254}		
        do ip addr add xxx.xxx.70.$i/24 dev em1		
done

I also tried single (like before) but on the next subnet and noticed this error.

Code:
root@server:~# sh addips.sh
Error: an inet prefix is expected rather than "xxx.xxx.58.{2..254}/24".
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d4:be:d9:f0:fc:44 brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.105.34/29 brd xxx.xxx.105.39 scope global em1
       valid_lft forever preferred_lft forever
    inet xxx.xxx.3.2/24 scope global em1

Last edited by Bashed; 11-22-2016 at 01:31 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
DHCP/BIND and ddns to update two subnets gudlyf Linux - Software 3 05-25-2012 02:33 PM
Bind issue with secondary master server deibertine Linux - Server 4 10-22-2009 11:21 PM
Bind - secondary server not receiving updates gwroy20 Linux - Software 1 12-09-2005 01:54 PM
DNS- Windows Primary, bind secondary mjstone03 Linux - General 0 09-27-2005 03:09 PM
BIND slave/secondary help Supp0rtLinux Linux - Software 1 07-29-2003 12:37 AM

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

All times are GMT -5. The time now is 05:46 PM.

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