How to set a temporary IP Address in Linux?

root@adil:~# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:aa:52:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.243/23 brd 192.168.5.255 scope global eth0
valid_lft forever preferred_lft forever

What are the valid_lft and preferred_lft?

ip addr add 192.168.4.244/23 dev eth0 valid_lft 10 preferred_lft 10
root@adil:~# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:aa:52:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.243/23 brd 192.168.5.255 scope global eth0
valid_lft forever preferred_lft forever
root@adil:~# ip addr change 192.168.4.244/23 dev eth0 valid_lft 10 preferred_lft 10root@ubuntu:~# curl --interface 192.168.4.244 192.168.4.71/ip.php
Your IP Address is: 192.168.4.244
root@adil:~# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:aa:52:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.243/23 brd 192.168.5.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.4.244/23 scope global secondary dynamic eth0
valid_lft 10sec preferred_lft 10sec
inet6 fe80::a00:27ff:feaa:5287/64 scope link
valid_lft forever preferred_lft forever
root@adil:~# sleep 10root@adil:~# curl --interface 192.168.4.244 192.168.4.71/ip.php
curl: (45) bind failed with errno 99: Cannot assign requested address

How about preferred_lft?

root@adil:~# ip addr change 192.168.4.244/23 dev eth0 valid_lft 100 preferred_lft 10root@adil:~# sleep 10root@adil:~# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:aa:52:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.243/23 brd 192.168.5.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.4.244/23 scope global secondary deprecated dynamic eth0
valid_lft 90sec preferred_lft 0sec

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Scraping Wallstreetbets for stocks signals

Null safety with kotlin

How to manage your project step-by-step

Algorithm

Knapsack problem using greedy method

How do I even learn Python?

Code structure

Translate SQL’s regexp_extract() in Microsoft SQL Server

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
adil

adil

More from Medium

Getting Started with Linux For Beginners

Linux

How to create Static Partition in Linux Operating System ?

How to manage your Docker containers with Portainer

Getting Started with Docker Swarm