LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Binding a list of IPv4 addresses to Ubuntu Server quickly (https://www.linuxquestions.org/questions/linux-newbie-8/binding-a-list-of-ipv4-addresses-to-ubuntu-server-quickly-4175564192/)

youbuntoo 01-17-2016 02:35 PM

Binding a list of IPv4 addresses to Ubuntu Server quickly
 
Hey Guys,

Is there a bash script or tool to automatically bind a list of IPv4 addresses to an Ubuntu server quickly?

For example, let's say I have a text file named /root/iplist.txt
and in iplist.txt, I have one IP per line:
1.1.1.1
1.1.1.2
1.1.1.3
... and so on, until .30 let's say. How do I automatically bind that list of individual IPv4 addresses to the Ubuntu server?

I am aware of the ip command to bind a CIDR block (ip addr add 1.1.1.1/24 for example) however I am not sure how to quickly bind a range of individual IPs.

I know how to do this in CentOS with ifcfg-eth1-range0 but it doesn't appear this feature is available in Ubuntu...

I am sure this topic will come in handy for a lot of other people as I was only able to find tutorials on how to do this with CentOS despite my hours of researching I was not able to find anything for Ubuntu. So I am adding the appropriate tags to this post :)

Thanks for any help,

youbuntoo 01-17-2016 06:06 PM

Anyone?

youbuntoo 01-17-2016 06:16 PM

Found the solution, in case anyone was needing this! I searched for hours and couldn't find anything so decided to come up with something on my own! I really hope this helps others who were seeking the same solution.

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

Replace 255.255.255.0 with your subnet, and replace 192.168.0. with the first 3 parts of your IP range
Edit "eth1" to eth0 or whatever your main network interface is.

And replace 1..128 accordingly, for example the above commnad would route .1 to .128.


All times are GMT -5. The time now is 10:59 PM.