Monday, April 23, 2007

Change IP on Linux

To change IP Address on Linux we have to had a root access.
I have tested this on Red Hat Linux AS 3.

After login as root then do the simple step below:

1. Modify the configuration file
with the command line:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
BROADCAST=172.26.11.255
IPADDR=172.26.11.192
NETMASK=255.255.0.0
NETWORK=172.26.11.0
ONBOOT=yes
TYPE=Ethernet


Then modify the entry IPADDR, NETMASK with
your own. You may change like this:

IPADDR=172.26.7.122

You may also modify other entry as you need,
then save the change.

2. Restart the network service with command line:

# /etc/init.d/network restart

If successed will look like below:

Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]


3. You may check the change with this command line:

# ifconfig -a

As a result the following information will display on the screen.
The eth0 interface has changed.

eth0 Link encap:Ethernet HWaddr 00:11:09:06:9A:24
inet addr:172.26.7.122 Bcast:172.26.11.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:673374 errors:0 dropped:0 overruns:0 frame:0
TX packets:513551 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:562369198 (536.3 Mb) TX bytes:92885906 (88.5 Mb)
Interrupt:11 Base address:0xec00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:53122 errors:0 dropped:0 overruns:0 frame:0
TX packets:53122 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1652248 (1.5 Mb) TX bytes:1652248 (1.5 Mb)

IP Security for Samba Server

I have linux samba server for folder sharing in my Local Area Network (LAN). Then I need only restricted IP addresses can access the specific folder. I do following simple steps:


1. I modify the configuration file (smb.conf) with the root user.

# vi /etc/samba/smb.conf

[private]
comment = Plita stuff
path = /data/private
valid users =plita
public = no
writable = yes
printable = no
create mask = 0765
hosts allow = 172.26.15.71 172.26.15.200 172.26.15.212

I add the IP addresses in the entry of hosts allow and sparate the IP with space if the IP that granted to access the folder more than one. Then save the changes.

2. I restart the samba service with the following command line:

# /etc/init.d/smb restart

In my screen then displayed message like the below:

Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]

3. Done. After this, only from the IP that has listed, the folder could be accessed.