192.168.0.* > 192.168.0.0 How with command line?
I'm trying to write a somewhat universal script for simple router configuration via iptables. I'm attempting to have the script get the information it needs from the `ip link` and `ip addr` commands. I can extract what I need easily.
My problem is how to change the lan interface ip from whatever it is, in my case 192.168.0.1 to 192.168.0.0 to make that entire subnet work in my iptables rules. 192.168.0.1 could be any ip in that subnet. So regardless of what it is I want to change the last field to 0. I am terrible with regex, my only experience of any kind involves delimiters and such with cut and awk Those just get me individual fields. How can I take any ip in that subnet to end up ending with a 0? My current script Code:
#!/bin/sh |
The regexp would be 192\.168\.0\.[1..9]+. That would give you any address with any number of digits (but at least one) as the fourth octet. I think you could do a for loop to find and reset addresses in that range.
|
I'll try that. It may be cleaner than what I found here. This is my current script with the loop.
Code:
#!/bin/sh |
Actually, in a given network, the first address is reserved as the address of the network itself and the last is the broadcast address.
For 192.168.0.0/24, that means 192.168.0.0 = network, 192.168.0.255 = broadcast. You shouldn't try to assign those 2. See eg http://www.jodies.de/ipcalc?host=192...ask1=24&mask2= for a nice easy ip calculator (there are many on the web). |
All times are GMT -5. The time now is 10:53 AM. |