Created Mon Jan, 22 2024 at 01:56AM
To temporarily configure an IP address, you can use the
ip command in the following manner. Modify the IP address and subnet mask to match your network requirements.
sudo ip addr add 10.102.66.200/24 dev enp0s25
ip can then be used to set the link up or down.
ip link set dev enp0s25 up
ip link set dev enp0s25 down
To verify the IP address configuration of
enp0s25, you can use the
ip command in the following manner:
ip address show dev enp0s25
10: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:16:3e:e2:52:42 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.102.66.200/24 brd 10.102.66.255 scope global dynamic eth0
valid_lft 2857sec preferred_lft 2857sec
inet6 fe80::216:3eff:fee2:5242/64 scope link
valid_lft forever preferred_lft forever6
To configure a default gateway, you can use the
ip command in the following manner. Modify the default gateway address to match your network requirements.
sudo ip route add default via 10.102.66.1
You can also use the
ip command to verify your default gateway configuration, as follows:
ip route show
default via 10.102.66.1 dev eth0 proto dhcp src 10.102.66.200 metric 100
10.102.66.0/24 dev eth0 proto kernel scope link src 10.102.66.200
10.102.66.1 dev eth0 proto dhcp scope link src 10.102.66.200 metric 100
If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file
/etc/resolv.conf. In general, editing
/etc/resolv.conf directly is not recommended, but this is a temporary and non-persistent configuration. The example below shows how to enter two DNS servers to
/etc/resolv.conf, which should be changed to servers appropriate for your network. A more lengthy description of the proper (persistent) way to do DNS client configuration is in a following section.
If you no longer need this configuration and wish to purge all IP configuration from an interface, you can use the
ip command with the flush option:
ip addr flush eth0