Showing posts with label network. Show all posts
Showing posts with label network. Show all posts

Friday, November 18, 2011

Network interface in Linux

How to reorder or rename logical interface names in Linux
===========================================================
$ sudo apt-get install ifrename
$ cat /etc/iftab
eth0 mac E0:*

Other ways are detailed at http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames


It's quite useful in case of install Linux on a virtual machine.

When we move the image to various hosts,
1) the interface name will keep running to eth1, eth2, eth3 and so on
2) the ip address will not automatically obtained.
because inside /etc/network/interfaces
....
iface eth0 inet dhcp
...


New method
=========
use the udev-sanctioned method of statically-naming each interface.
Create the following file to bind the MAC address of each of your cards to a certain interface name:
/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net" KERNEL=="eth*", ATTR{address}=="00:12:34:fe:dc:ba", NAME="eth0"

note:
  • To get the MAC address of each card, use this command: cat /sys/class/net/device-name/address
  • When syntax errors, look at /etc/udev/rules.d/70-persistent-net.rules
  • Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.

  • When choosing the static names it should be avoided to use "ethX" and "wlanX", because this may lead to race conditions between the kernel and udev during boot. Instead, it is better to use interface names that are not used by the kernel as default, e.g. "net0, net1, wifi0, wifi1".


Ref:
http://www.debianhelp.co.uk/udev.htm
https://wiki.archlinux.org/index.php/Udev#Network_device

Thursday, September 29, 2011

commands for wireless lan in debian

After a fresh install of wheezy

sudo ifconfig -a
sudo ifconfig wlan0 up
SIOCSIFFLAGS: Operation not possible due to RF-kill

#rfkill : tool for enabling and disabling wireless devices
sudo apt-get install rfkill

$ sudo rfkill list
0: asus-wlan: Wireless LAN
    Soft blocked: no
    Hard blocked: no
1: asus-bluetooth: Bluetooth
    Soft blocked: no
    Hard blocked: no
2: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no


sudo rfkill unblock 0
sudo rfkill unblock 2

sudo rfkill unblock wifi
sudo rfkill unblock wlan

sudo ifconfig -a
sudo ifconfig wlan0 up

# iwconfig modu = force the card to only use the specific set of modulations
sudo iwconfig wlan0 modu 11g

sudo iwlist wlan0 scanning

sudo iwconfig wlan0 mode Managed

sudo iwconfig wlan0 essid {name}

#eg: sudo iwconfig wlan0 essid "My Router"

sudo iwconfig wlan0 channel {channel number}

# WEP encryption
sudo iwconfig wlan0 key {hex digit}

#eg: sudo iwconfig wlan0 key 0123-4567-89

sudo iwconfig

# dhclient -r : to avoid "RTNETLINK answers: File exists" when reconnect network after standby or hibernate
sudo dhclient -r wlan0

sudo dhclient wlan0
sudo ifconfig wlan0



To avoid soft blocked again after reboot add

options ath_pci rfkill=0
options ath_pci rfkill=1
options ath_pci rfkill=2
... (depend on rfkill list)

to /etc/modprobe.d/ath.conf
(any new file with .conf extension)

or
insert 'rfkill unblock wlan' in /etc/rc.local


ifup - ifdown
==========
# my /etc/network/interfaces is
auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet dhcp
wpa-ssid my_ssid
wpa-psk my_password_shared_key
wpa-key-mgmt WPA-PSK

# now we can bring our interface up and down with the usual ifup and ifdown commands
sudo ifup wlan0
sudo ifdown wlan0

# The "auto" stanza will bring your interface up at system startup.
# If not desired, remove or comment this line.

wpa useful command
================
sudo wpa_cli
zcat /usr/share/doc/wpasupplicant/README.modes.gz | less


Thanks:
Google
http://axcoto.com/blog/article/tag/siocsifflags-operation-not-possible-due-to-rf-kill
http://www.project4fun.com/node/36 shows commands and outputs
http://wiki.debian.org/WiFi/HowToUse#wpasupplicant

Saturday, July 16, 2011

IP Addr and Internet Name - Part 1 Commands

cat /etc/resolv.conf

BIND
====
BIND is an acronym for the Berkeley Internet Name Domain project,
which is a group that maintains the DNS-related software suite that runs under Linux.
The most well known program in BIND is named, the daemon that responds to DNS queries from remote machines.

ref: http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch18_:_Configuring_DNS


The Host Command
=================
The host command accepts arguments that are either the fully qualified domain name
or the IP address of the server when providing results. To perform a forward lookup,
use the syntax:

[root@bigboy tmp]# host www.linuxhomenetworking.com
www.linuxhomenetworking.com has address 65.115.71.34


The nslookup Command
=====================
The nslookup command provides the same results on Windows PCs. To perform forward lookup, use.

sudo apt-get install dnsutils

s@penguin:~$ nslookup portal.trueinternet.co.th
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
Name: portal.trueinternet.co.th
Address: 61.91.230.178

authoritative = ซึ่งเชื่อถือได้


dig
====
dig {domain.to.lookup}

>> look in /etc/resolv.conf file and querying the DNS servers listed there.

s@penguin:~$ dig portal.trueinternet.co.th +nocmd +nostats +noquestion

; <<>> DiG 9.7.3 <<>> portal.trueinternet.co.th +nocmd +nostats +noquestion
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47978 ;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; WARNING: recursion requested but not available ;; ANSWER SECTION: portal.trueinternet.co.th. 531 IN A 61.91.230.178 s@penguin:~$ dig portal.trueinternet.co.th ; <<>> DiG 9.7.3 <<>> portal.trueinternet.co.th
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27376
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;portal.trueinternet.co.th. IN A

;; ANSWER SECTION:
portal.trueinternet.co.th. 243 IN A 61.91.230.178

;; Query time: 4 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Thu May 26 09:25:52 2011
;; MSG SIZE rcvd: 59


Lines beginning with ; are comments that are not part of the information received from the DNS server

the RA flag shows that recursive queries are available.

The IN means this is an Internet lookup (in the Internet class).

The A record stores the host IP address.
The CNAME is an alias record, which is used to give multiple aliases to a single computer.
The MX record is the mail exchange record, which tells mail servers how to route email for this domain.

* to query other DNS servers
dig @ns.hosteurope.com www.hungrypenguin.net


Ref: http://www.linux.com/learn/tutorials/442431-check-your-dns-records-with-dig


List open ports and listening services
$ netstat -an
# -n : to get port numbers instead of having the utility try to provide names for services
$ netstat -lnptu

$ sudo apt-get install nmap
$ nmap localhost

$ sudo apt-get install sockstat
$ sockstat

then
$ grep -w 631 /etc/services


Fix IP
=======
sudo vi /etc/network/interfaces
replace
  allow-hotplug eth0
  iface eth0 inet dhcp
with
  auto eth0
  iface eth0 inet static
  address 192.168.1.36
  netmask 255.255.255.0
  gateway 192.168.1.1
  dns-nameservers 192.168.1.1

sudo ifconfig eth1 192.168.2.3 netmask 255.255.255.0
sudo route add default gw 192.168.2.1 eth1

more info: http://www.cyberciti.biz/faq/setting-up-an-network-interfaces-file/

How do I find out my DHCP server address?

ถ้าเชื่อมต่อด้วย dhclient

ls -t -l /var/lib/dhcp/
# List ไฟล์ โดยเรียง modification time ด้วยคำสั่ง

แล้วก็ vi ดูไฟล์ที่ถูกแก้ไขล่าสุด

ตัวอย่าง output

lease {
interface "eth0";
fixed-address 192.168.1.49;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 192.168.1.1;
option dhcp-server-identifier 192.168.1.1;
option vendor-class-identifier 0:0;
option vendor-encapsulated-options 1:4:43:54:43:30;
option domain-name "domain.name";
option vendor.unknown-3561 4:6:30:30:45:30:34:43:5:8:30:30:30:30:30:30:30:31:6:3:49:47:44;
renew 4 2011/05/26 11:52:46;
rebind 4 2011/05/26 22:46:45;
expire 5 2011/05/27 01:46:45;
}