Network connection from command line
Hi,
I have wireless card and can connect to Internet using network-admin. It is fine, but I want to do the same from command line. In Ubuntu community I found "WiFiHowto" page which recommends "ifup" and ifdown" commands. When I try
> ifup eth0
I get message
"eth0=eth0 interface doesn't exist"
or something like that (I don't remember exactly). But if I run
> iwconfig
responce looks like
...
* eth0 IEEE 802.11g ESSID:"NETGEAR"
...
(I ommited lines for more details and for loopback interface)
My assumption is these commands require configuration of /etc/network/
So, is there any command-line analogue to network-admin using the same configuration data? Or may be I misunderstood process of network configuration?
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Last query:
- 2007-08-17
- Last reply:
- 2007-08-18
| Basilio Kublik (sourcercito) said : | #1 |
Hi Alexander
if you configure your wireless interface in /etc/network/
wep encryption with dhcp:
================
user@machine:~$ sudo ifconfig eth0 up
user@machine:~$ sudo iwconfig essid "My-AP-Name" key s:my_secret_wepkey
user@machine:~$ sudo dhclient eth0
wep encryption with static ip:
=================
user@machine:~$ sudo ifconfig eth0 10.10.10.2 netmask 255.255.255.0 up
user@machine:~$ sudo route add -net 10.10.10.0 netmask 255.255.255.0 gw 10.10.10.1 eth0
user@machine:~$ sudo iwconfig essid "My-AP-Name" key s:my_secret_wepkey
dhcp without encryption:
===============
user@machine:~$ sudo iwconfig eth0 essid "My-AP-Name"
user@machine:~$ sudo dhclient eth0
now this examples should look like this in the interfaces file:
wep encryption with dhcp:
=================
auto eth0
iface eth0 inet dhcp
wep encryption with static ip:
=================
auto eth0
iface eth0 inet static
address 10.10.10.2
netmask 255.255.255.0
gateway 10.10.10.1
dhcp without encyption:
==============
auto eth0
iface eth0 inet dhcp
now in my opinion the most interesting way to configure it is using wpa_supplicant, works for open networks, wep encrypted and wpa/2 personal and enterprise.
first we need some examples of wpa_supplicant.conf file, i'll give you one of each option.
#### start of wpa_supplicant.conf file ####
ctrl_interface=
ctrl_interface_
eapol_version=1
ap_scan=1
fast_reauth=1
### any open network ###
network={
ssid=""
}
### wep encrypted network ###
network={
}
### wpa personal encrypted network ###
network={
proto=WPA
group=CCMP TKIP
psk="My super secret paraphrase that could contain spaces"
priority=3
}
### wpa enterprise encrypted network ###
network={
proto=WPA
group=CCMP TKIP
eap=TLS
<email address hidden>"
}
### end of wpa_supplicant.conf ###
now to user wpa2 instead of wpa, you just need to change the proto from WPA to WPA2.
so you want to connect to a network using wpa_supplicant, first you need to start the wpa_supplicant process:
user@machine:~$ sudo ifconfig eth0 up
user@machine:~$ sudo /usr/bin/
user@machine:~$ sudo ifconfig eth0 add 10.10.10.2 netmask 255.255.255.0
user@machine:~$ sudo route add -net 10.10.10.0 netmask 255.255.255.0 gw 10.10.10.0 eth0
of course if you use dhcp in this last case, you could skip the ifconfig/route commands and use dhcpclient after you start the wpa_supplicant process.
user@machine:~$ sudo /usr/bin/
user@machine:~$ sudo dhclient eth0
now, this could be done via interfaces file as well, and here is how:
### WPA with DHCP ###
auto eth0
iface eth0 inet dhcp
wpa-ssid My-AP-Name
wpa-driver wext
wpa-conf /etc/wpa_
### WPA with static IP ###
auto eth0
iface eth0 inet static
wpa-ssid My-AP-Name
wpa-driver wext
wpa-conf /etc/wpa_
address 10.10.10.2
netmask 255.255.255.0
gateway 10.10.10.1
note that in those last two examples of the interfaces file, the ssid is mentioned just for set is as preferred network.
with any of the configurations in your interfaces file you can use ifup/ifdown commands.
for more detailed, and maybe more clear information or if you have a more exotic network you could look at:
man 7 wireless
man 5 interfaces
man 8 wpa_supplicant
man 8 route
man 8 ip
man 8 ifconfig
hope this solve your question, instead of boring you or give you a headache.
| Alexander Zemerov (azemerov) said : | #2 |
Basilio,
Thank you. It was helpful information. I didn't know about wpa_supplicant.
But actually my question was - can I avoid _any_ manual configuration and use current configuration prepared by network-admin? I understand there are several ways to control network in Linux, each uses it's own set of configuration files. I can easily configure /etc/network/
Again, it is not actual problem, just curiosity. Right now I use ifupdown + /etc/network/
| Basilio Kublik (sourcercito) said : | #3 |
now i get what you want, unfortunately i only remember one piece of ancient software that i use a couple of times, this is linuxconf, a curses based interface to admin almost anything from users to services, i really don't know if at some point they add wireless networking support, but you could look it anyway just to find out.
the other not so close approach could be wifi-radar, which can be configured using an pygtk interface under X or editing by hand the configuration file, and can be run as daemon, so it should connect to any open or configured network at boot time.
and the last think i could think of at the moment is the wpa_supplicant approach, but you should configure by hand anyway so i don't think that's what you're looking for.
at the moment that's all i can remember/think of that could "satisfy" in some way your need.
but even if you don't find any real solution to this, you can always start a new blueprint with the specs of what you want, and probably more than one person will follow you.
hope that's of any useful help.
Can you help with this problem?
Provide an answer of your own, or ask Alexander Zemerov for more information if necessary.

