0

I have the following problem: I want to change the netmask of large number of ip adresses in Debian's /etc/network/interfaces because I am going to expand the network. After changing it I will use screen ifdown ens18 && ifup ens18 to apply the changes. The substitution of the netmask works in my example, the problem is that I need to keep the 26 unchanged in the ip address. I have a sed line which changes all twenty-sixes to 25 but of course this is not what I want.

I have:

iface ens18 inet static
    address 195.26.153.26/26

I want:

iface ens18 inet static
    address 195.26.153.26/25

How can I achieve this?

1 Answer 1

1

To match only the netmask, match it with the separator:

sed sX/26X/25X

If you’re sure the netmask is at the end of a line, you can constrain the matches further:

sed 'sX/26$X/25X'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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