How to make "ip addr add 192.168.1.77 dev eth1" permanent?

I need to add an address on the LAN side of a router. It's easiest if I can put it on the existing subnet 192.168.1.0/24 given in config/network:

config interface 'lan1'                                                                              
    option ifname 'eth1'                                                                             
    option proto 'static'                                                                            
    option ipaddr '192.168.1.1'                                                                     
    option netmask '255.255.255.0'                                                                   

I can succesfully add a temporary address using

ip addr add 192.168.11.77 dev eth1

which shows up:

# ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0xxxxxxxxxxx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.11.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet 192.168.1.77/32 scope global eth1
       valid_lft forever preferred_lft forever

and successfully ping it.

On OpenWRT (how) can it be made permanent via a config file?

I looked at the this example for a non-bridge interface, changing it to use the same subnet:

config interface 'lan1-77'                                                                              
    option ifname 'eth1'                                                                             
    option proto 'static'                                                                            
    option ipaddr '192.168.1.77'                                                                     
    option netmask '255.255.255.0'

however it hung on boot. (Maybe the '-' was illegal?).

Could you explain what you are trying to achieve? Do you have a number of devices that you want to separate them form your main network? Do you want to create a separate VLAN (or AP) for gusts?

Meanwhile, check this [Solved] Two IP Addresses in the same net

Perhaps, I see nothing wrong with the config...so long as you're only adding a second IP for use on LAN...you may have to use @lan instead of eth1. Try an underscore.

As stated and given the OP's config...this only allows them to separately address and block devices on the same VLAN, for services on/through the router.

2 Likes
4 Likes

What you need is an alias: https://openwrt.org/docs/guide-user/network/network_interface_alias

2 Likes

An alternative approach is switching to CIDR list notation by replacing

option ipaddr '192.168.1.1'
option netmask '255.255.255.0'

with

list ipaddr '192.168.1.1/24'
list ipaddr '192.168.1.77/32'
5 Likes

The simplest solution that works for my use case.

For completeness sake, I tested the advice of @lleachii @vgaetera
rewrote the original config

config interface 'lan1_77'                                                                              
    option ifname 'eth1'                                                                             
    option proto 'static'                                                                            
    option ipaddr '192.168.1.77'                                                                     
    option netmask '255.255.255.255'

This also worked. However the chosen solution is much more succinct in my use case. If however one needed/preferred a separate interface name (lan1_77) for referencing in other config files, then this would be the way to go.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.