LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Setting static IP (https://www.linuxquestions.org/questions/linux-newbie-8/setting-static-ip-4175468784/)

NotionCommotion 07-07-2013 12:52 PM

Setting static IP
 
Why doesn't ifconfig show wlan0's IP address as 192.168.0.200? How do I make it do so. Sometimes I can SSH into it using 192.168.0.200, but other times only 192.168.0.104 seems to work.

Why do I have identical files at:
/etc/sysconfig/networking/profiles/default/ifcfg-wlan0
/etc/sysconfig/networking/devices/ifcfg-wlan0
/etc/sysconfig/network-scripts/ifcfg-wlan0

Thank you

Code:

[root@desktop ~]# cat /etc/sysconfig/networking/profiles/default/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
HWADDR=88:51:fb:51:df:70
IPV6INIT=yes
IPV6_AUTOCONF="yes"
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID="e636c50d-822a-498b-8156-3c3b75d4fe4b"
USERCTL=no
IPADDR=192.168.0.201
NETMASK=255.255.255.0
DNS2=8.8.4.4
GATEWAY=192.168.0.1
DNS1=8.8.8.8

[root@desktop ~]# cat /etc/sysconfig/networking/devices/ifcfg-wlan0
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DEVICE=wlan0
BOOTPROTO=none
NETMASK=255.255.255.0
DNS2=8.8.4.4
TYPE=Wireless
HWADDR=b8:76:3f:69:31:95
IPADDR=192.168.0.200
IPV6INIT=no
ONBOOT=yes
USERCTL=no

[root@desktop ~]# cat /etc/sysconfig/network-scripts/ifcfg-wlan0
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DEVICE=wlan0
BOOTPROTO=none
NETMASK=255.255.255.0
DNS2=8.8.4.4
TYPE=Wireless
HWADDR=b8:76:3f:69:31:95
IPADDR=192.168.0.200
IPV6INIT=no
ONBOOT=yes
USERCTL=no

[root@desktop ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 88:51:FB:51:DF:70
          inet addr:192.168.0.201  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0    Link encap:Ethernet  HWaddr B8:76:3F:69:31:95
          inet addr:192.168.0.104  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ba76:3fff:fe69:3195/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2098 errors:0 dropped:0 overruns:0 frame:0
          TX packets:579 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:418993 (409.1 KiB)  TX bytes:95179 (92.9 KiB)

[root@desktop ~]#


Linux MR 07-07-2013 08:34 PM

I'm most familiar with Red Hat and Fedora and the setting to make the IP static is bootproto

Quote:

file: /etc/sysconfig/network-scripts/ifcfg-<device>
parameter: BOOTPROTO=static
After setting the BOOTPROTO I would suggest restarting the network service.

Hope that helps

frankbell 07-07-2013 09:13 PM

What distro are you using? How to set a static IP address can vary depending on the init system of your distro.

NotionCommotion 07-07-2013 09:52 PM

Thank you Gents,

I am using CentOS 6.4.

The eth0 files seem to have been made magically, by me but I forgot, or after I used system-config-network.

I know I manually copied one of the wlan0 files, and modified another to make them look the same in an attempt to mimic the eth0 files.

If only one of the three is important, I wish to only modify those and ignore the rest.

Thanks again for your help.

frankbell 07-07-2013 09:55 PM

CentOS works like RHEL.

This should help:

http://www.broexperts.com/2013/03/ho...in-centos-6-3/

Madhu Desai 07-08-2013 01:30 AM

@NotionCommotion

1.In Redhat/CentOS/SL/OL,

ethX = Ethernet Physical connection
wlan0 - Wireless connection

2.You should not edit manually files under '/etc/sysconfig/networking/' directory. It is used by 'system-config-network' tool, which redhat says is now deprecated. You should use files under '/etc/sysconfig/network-scripts/' ONLY.

3. Which do you have/use - Physical connection(eth) or Wireless connection(wlan)? Remove the other irrelevant file.

Typical ifcfg-eth0 sample for static IP:
Quote:

DEVICE=eth0
NAME="System eth0"
TYPE=Ethernet

ONBOOT=yes
BOOTPROTO=none
#NM_CONTROLLED=yes

IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1

DNS1=8.8.8.8
DNS2=8.8.4.4

DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERCTL=no
#NM_CONTROLLED=yes (use this if you want NetworkManager to control the connection (little two computers icon in system tray).
PREFIX=24 (Alternative NETMASK=255.255.255.0)

After editing file (in /network-scripts/), restart service to take effect

Depending on your configuration

Code:

# service network status
# service NetworkManager status

# service network restart
# service NetworkManager restart


NotionCommotion 07-08-2013 08:25 AM

Thank you Frank,

I made the changes per the Bros Experts. Specifically, changes from my existing...

/etc/sysconfig/network-scripts/ifcfg-wlan0
Code:

BOOTPROTO="static"
NM_CONTROLLED="no" #Was none

/etc/sysconfig/network
Code:

GATEWAY=192.168.1.100 #Added
/etc/resolv.conf
Code:

nameserver 192.168.1.200 #Added before nameserver 8.8.8.8 and nameserver 8.8.4.4
Unfortunately, lost ssh communication to my server :(

What actions were made by these changes, and why do you think I lost communication?

NotionCommotion 07-08-2013 09:10 AM

mddesai, I appreciate the "whys" you should do something. Thank you

Quote:

2. You should not edit manually files under '/etc/sysconfig/networking/' directory. It is used by 'system-config-network' tool, which redhat says is now deprecated. You should use files under '/etc/sysconfig/network-scripts/' ONLY.
Thank you, great information. Should I just modify /etc/sysconfig/network-scripts/ manually? Do I not worry about the other two since I will no longer using system-config-network?

Quote:

3. Which do you have/use - Physical connection(eth) or Wireless connection(wlan)? Remove the other irrelevant file.
wlan, however, if wlan stops, I want like to default upon eth, however, it isn't 100% necessarily. Confirm you are recommending I delete /etc/sysconfig/network-scripts/eth0 in its entirety. I am not using NetworkManager, and this is probably the reason I lost communication (see previous post to Frank)

Below is the new /etc/sysconfig/network-scripts/wlan0 I propose to use. Look good? Please check out my comment/questions throughout it.
Code:

DEVICE=wlan0 #Changed to wireless
NAME="System wlan0"
TYPE=Wireless

ONBOOT=yes
BOOTPROTO=none #Why not static?
#NM_CONTROLLED=yes

IPADDR=192.168.0.100 #Note 1 was change to 0
PREFIX=24 #What does this do?  Why not using NETMASK?
# NETMASK=255.255.255.0
GATEWAY=192.168.0.1

DNS1=8.8.8.8
DNS2=8.8.4.4

#Please describe why you include these
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERCTL=no

#There were not on your list.  Please describe why
UUID="e636c50d-822a-498b-8156-3c3b75d4fe4b"
HWADDR=88:51:fb:51:df:70


jpollard 07-08-2013 09:15 AM

BOOTPROTO=none is to tell the startup code NOT to try things like DHCP, which can change all kinds of things.

PREFIX=24 defines the same (and used) the same way as netmask. The advantage is that it can also work for IPv6 where netmasks get horribly complicated.

DEFROUTE=yes is so you get a default route. If you have more than one network interface, only one of them should have "yes", the others "no". Or just the one you want to use for your default route. In my case, I have it on the second network interface. The first one is my internal net, the second is the route to the internet.

IPV4_FAILURE_FATAL=yes will stop the boot process because you are telling the system that you MUST have IPv4 available.

IPV6INIT=no is to disable the use of IPv6. This is sometimes useful because some ill-mannered applications will not handle DNS lookups if a lookup fails on IPv6, and doesn't try an IPv4 lookup. Disabling IPv6 forces all applications to use IPv4 only.

USERCTL=no prevents users from doing things to this interface.

Mousepad123 07-08-2013 09:27 AM

Although this issue looks as though it's been solved, I would like to say one thing:

If you need to set a temporary static IP, you can use this command:

Code:

ifconfig eth0 192.168.1.2/24
(that would set the IP of adapter eth0 to 192.168.1.2 with a netmask of 24 (255.255.255.0) until you reboot)

NotionCommotion 07-08-2013 09:35 AM

Thanks jpollard,

Just to confirm, BOOTPROTO=static is something I definitely do not want, correct?

Madhu Desai 07-08-2013 10:18 AM

Quote:

Originally Posted by NotionCommotion (Post 4986211)
Should I just modify /etc/sysconfig/network-scripts/ manually? Do I not worry about the other two since I will no longer using system-config-network?

Redhat in its documentation, has clearly mentioned NOT to use anything under /sysconfig/networking/ and SHOULD only use scripts under /sysconfig/network-scripts/. (links I have attached below).

Either you edit the script, or Network Manger edits the script, both are written to same script that are under /sysconfig/network-scripts/ - in order who edits it last. Exactly why scripts under /sysconfig/networking/ are used I don’t know, but whatever you do to scripts in /network-scripts/ are updated to /networking/, so eventually both will be same. However, Redhat says it is now depreciated.

Its your wish if you want to use Network Manager or not. Personally I feel its redundant, so I don’t use it (chkconfig NetworkManager off)
Quote:

Originally Posted by NotionCommotion (Post 4986211)
wlan, however, if wlan stops, I want like to default upon eth, however, it isn't 100% necessarily. Confirm you are recommending I delete /etc/sysconfig/network-scripts/eth0 in its entirety.

If you are using both interfaces, you don't have to delete. let them be there. no harm ;)
Quote:

Originally Posted by NotionCommotion (Post 4986211)
Below is the new /etc/sysconfig/network-scripts/wlan0 I propose to use. Look good? Please check out my comment/questions throughout it.

To be frank, I have never setup wireless devices – only servers and desktops with wired connections. So I'm unaware of wireless LAN setup HOWTO.
Quote:

Just to confirm, BOOTPROTO=static is something I definitely do not want, correct?
I think you can put either none or static. both are same.

Links:
Chapter 8. NetworkManager (GUI Tool)
Chapter 9. Network Interfaces (For manual edit)
Red Hat Enterprise Linux 6 Deployment Guide (Full book online)
Red Hat Enterprise Linux 6 Deployment Guide (PDF Download - Right click and save)

jpollard 07-08-2013 10:20 AM

Quote:

Originally Posted by NotionCommotion (Post 4986227)
Thanks jpollard,

Just to confirm, BOOTPROTO=static is something I definitely do not want, correct?

"static" is no longer defined. The only valid values for BOOTPROTO are:

none — No boot-time protocol should be used.
bootp — The BOOTP protocol should be used.
dhcp — The DHCP protocol should be used.

From http://www.centos.org/docs/2/rhl-rg-...rkscripts.html (which is a bit dated)
and: https://github.com/cobbler/cobbler/issues/361 (which is the most recent, and over a PXE boot bug where "static" was still accepted)

Madhu Desai 07-08-2013 11:07 AM

Regarding parameters in ethernet config file, jpollard has already explainted it right.

About UUID, it is genetrated by Network Manager tool to differentiate between different inerfaces. unless you use NetworkManager you can remove this parameter safely.

HWADDR, are physical hardware address embedded in NIC. unless you have more than one NIC, you can also ignore this parameter too.

More about these parameters are in 2nd-4th page of document i have posted. (Chapter 9. Network Interfaces)

NotionCommotion 07-08-2013 12:24 PM

Thank you all for your help.

I made the changes, and ifconfig still shows a different IP than 192.168.0.200. See below. Note that I can PuTTY into the server using either 192.168.0.106 or 192.168.0.200. Any thoughts why?

If I have both a wireless NIC and a CAT-5 NIC, any reason for HWADDR?

PS. Why am I setting up wireless on a server one might ask? It is only for development purposes, is located in my garage, and just didn't want to deal with running wire.


Code:

[root@desktop ~]# cat /etc/sysconfig/network-scripts/ifcfg-wlan0
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.

DEVICE=wlan0
NAME=wlan0
TYPE=Wireless

ONBOOT=yes
BOOTPROTO=none
#NM_CONTROLLED=yes

IPADDR=192.168.0.200
PREFIX=24
# NETMASK=255.255.255.0
GATEWAY=192.168.0.1

DNS1=8.8.8.8
DNS2=8.8.4.4

DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERCTL=no

[root@desktop ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 88:51:FB:51:DF:70
          inet addr:192.168.0.201  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0    Link encap:Ethernet  HWaddr B8:76:3F:69:31:95
          inet addr:192.168.0.106  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ba76:3fff:fe69:3195/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1315 errors:0 dropped:0 overruns:0 frame:0
          TX packets:120 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:388810 (379.6 KiB)  TX bytes:19225 (18.7 KiB)

[root@desktop ~]#



All times are GMT -5. The time now is 08:26 AM.