Ask Your Question
0

how to change IP address

asked 2017-01-05 18:09:16 -0500

afodata gravatar image

I have installed Fedora 25. I configured it with a static IP by editing the ifcfg file. I cannot figure out how to restart network so I had to reboot it to get the static to work. The static works fine. Now I want to change the IP and I really need to be able to restart the network and not have to reboot every time. systemctl restart NetworkManager.service does nothing ... the old IP remains also systemctl restart network.service just errors out. How do I restart the network?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-01-05 18:32:16 -0500

aeperezt gravatar image

You could use:

sudo ifdown dev
sudo ifup dev

To disconnect and reconnect the device. You could use nm-connection-editor to edit network information and apply it.

Hope this help.

edit flag offensive delete link more

Comments

problem is ... I usually do this from a remote terminal ... so there would be no way to do the ifup .. and to address the possible next question ... I usually change the IP, restart the network, then login to ssh again with the new IP

afodata gravatar imageafodata ( 2017-01-05 19:37:04 -0500 )edit

Simple build a small script that will do the ifdown and then ifup of cource you will lose the connection and will have to connect with the other IP after that something like:

#/bin/bash
ifdown eth0
ifup eth0

When you run it run it with like sudo net-restart.sh &

Hope this help.

aeperezt gravatar imageaeperezt ( 2017-01-05 20:51:47 -0500 )edit

Just a small detail. I think it isn't "eth0" any more but "enp2s0".

MaoTao gravatar imageMaoTao ( 2017-01-06 06:01:11 -0500 )edit

yes, of course it should not be eth0, I used as sample he need to figured out what is the interface name. :-)

aeperezt gravatar imageaeperezt ( 2017-01-06 10:20:04 -0500 )edit
0

answered 2017-01-07 02:38:30 -0500

First, the only way to really be sure that changing the address of an interface won't lock you out is by connecting to a different interface, or physical access.

If systemctl restart NetworkManager doesn't do anything, then you have broken services on the system that are functional by default. Read your logs, and correct any issues you discover.

To get the interface up so you can connect and work on that, use ip, like this:

[randomuser@ ~]$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether r8:4c:5t:3e:5i:d1 brd ff:ff:ff:ff:ff:ff
3: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether r8:4c:5t:3e:5i:d2 brd ff:ff:ff:ff:ff:ff

Interfaces that say NO-CARRIER don't have a cable connected. We're going to work with eno1, then.

[randomuser@ ~]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether r8:4c:5t:3e:5i:d1 brd ff:ff:ff:ff:ff:ff
3: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether r8:4c:5t:3e:5i:d2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.4/24 scope global eno1
       valid_lft forever preferred_lft forever
[randomuser@ ~]$ sudo ip addr add 192.168.0.4/24 dev eno1                                                                             

[randomuser@ ~]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether e8:40:f2:3e:44:d1 brd ff:ff:ff:ff:ff:ff
3: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master home0 state UP group default qlen 1000
    link/ether e8:40:f2:3e:44:d2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.4/24 scope global eno1
       valid_lft forever preferred_lft forever

Next you need to tell it about the router. Use ip to set the default gateway:

[randomuser@ ~]$ ip route 
192.168.0.0/24 dev eno1  proto kernel  scope link ...
(more)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-05 18:09:16 -0500

Seen: 649 times

Last updated: Jan 07 '17