Thanks for visiting! If you're new here, you may want to subscribe to my RSS feed. This blog posts regular tutorials, news, and study tips about networking, especially about Cisco CCIE related topics. Go ahead, subscribe to the feed! You can also receive updates from this blog via email. Thanks for visiting!
Need a basic web server? Did you know that little Cisco router in the corner can act as as one? Well, now you do! In this article we will be setting up a basic web server on a cisco router. I will be using dynamips to demonstrate this, but it works just as well on a real router! I was using dynamips to simulate a QOS lab where i wanted to mark certain HTTP traffic for shaping. I needed a way to simulate a web server so that I could test it. Enter the ip http server command!
We will be setting up this topology:

I will bridge f0/0 on the virtual R3 to my real lan. This way I can transfer the files i need to my virtual router using tftp. So first we need to set up dynamips so that f0/0 on R3 is bridged to my computers ethernet card. When you install Dynagen it creates a command script called Network device list.cmd. This script displays your network cards with device names that dynamips can refer to.
When run it produces something like this:

The red circle is the part we are interested in. That is how dynamips refers to our physical network card. In our .net file for dynamips we will bridge a virtual interface to this physical interface.
To do this, we create a .net file (webserver.net) with the following contents:
ghostios = true
sparsemem = true
model = 3640
[localhost]
[[3640]]
image = \Program Files\Dynamips\images\c3640-jk9o3s-mz.124-12.bin
# On Linux / Unix use forward slashes:
# image = /opt/7200-images/c7200-jk9o3s-mz.124-7a.image
ram = 96
[[ROUTER R1]]
s1/0 = R2 s1/0
[[ROUTER R2]]
s1/1 = R3 s1/0
[[ROUTER R3]]
f0/0 = NIO_gen_eth:\Device\NPF_{064084F0-A2EA-45FA-A362-ADDBC779026C}
This sets up the topology shown above, with R3’s f0/0 bridged to our physical network card. Now all we need to do is add an ip address to R3’s f0/0 thats in the same subnet as our physical network card and we should have connectivity between the two.
R1 Configuration:
hostname R1
!
int s1/0
ip add 10.0.12.1 255.255.255.0
no shut
!
router ospf 1
network 10.0.12.1 0.0.0.0 area 0
R2 Configuration:
hostname R2
!
int s1/0
ip add 10.0.12.2 255.255.255.0
no shut
!
int s1/1
ip add 10.0.23.2 255.255.255.0
no shut
!
router ospf 1
network 10.0.12.2 0.0.0.0 area 0
network 10.0.23.2 0.0.0.0 area 0
R3 Configuration:
hostname R3
!
int s1/0
ip add 10.0.23.3 255.255.255.0
no shut
!
int f0/0
ip add 192.168.1.100 255.255.255.0
no shut
!
router ospf 1
network 10.0.23.3 0.0.0.0 area 0
I have added an ip address to the R3 f0/0 interface that’s in the same subnet as my computer (192.168.1.0/24), so lets see if they can ping each other.
R3#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 2 subnets
O 10.0.12.0 [110/128] via 10.0.23.2, 00:00:10, Serial1/0
C 10.0.23.0 is directly connected, Serial1/0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
R3#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/48/116 ms
You can see the virtual R3 has connectivity to the physical host machine (192.168.1.1)! I’ve set up a tftp server on my host machine using tftpd32. I will use the tftp server to put files on R3 that i can serve out using the IOS webserver.
R3#copy tftp flash:
Address or name of remote host []? 192.168.1.1
Source filename []? picture.gif
Destination filename [picture.gif]?
Accessing tftp://192.168.1.1/picture.gif...
Erase flash: before copying? [confirm]n
Loading picture.gif from 192.168.1.1 (via FastEthernet0/0): !
[OK - 90 bytes]
Verifying checksum... OK (0xA319)
90 bytes copied in 0.216 secs (417 bytes/sec)
R3#copy tftp flash:
Address or name of remote host [192.168.1.1]? 192.168.1.1
Source filename [picture.gif]? picture.jpg
Destination filename [picture.jpg]?
Accessing tftp://192.168.1.1/picture.jpg...
Erase flash: before copying? [confirm]n
Loading picture.jpg from 192.168.1.1 (via FastEthernet0/0): !
[OK - 329 bytes]
Verifying checksum... OK (0x7656)
329 bytes copied in 0.244 secs (1348 bytes/sec)
R3#copy tftp flash:
Address or name of remote host [192.168.1.1]? 192.168.1.1
Source filename [picture.jpg]? index.html
Destination filename [index.html]?
Accessing tftp://192.168.1.1/index.html...
Erase flash: before copying? [confirm]n
Loading index.html from 192.168.1.1 (via FastEthernet0/0): !
[OK - 174 bytes]
Verifying checksum... OK (0xA4BA)
174 bytes copied in 0.264 secs (659 bytes/sec)
R3#dir
Directory of flash:/
1 -rw- 90 <no> picture.gif
2 -rw- 329 <no> picture.jpg
3 -rw- 174 <no> index.html
8388604 bytes total (8387812 bytes free)
</no></no></no>
You can see above that we copied three files (picture.jpg, picture.gif and index.html) to R3. These are the files that will make up a basic webpage that we are serving out.
Lets set up the web server:
R3(config)#ip http server
R3(config)#ip http path flash:
The ip http server command activates the built in IOS webserver. By default this command will first look for a file called home.html on any filesystem. If this file exists it will serve this page. If this file doesn’t exist it then looks for a file called home.shtml on any filesystem. If this is not found, by default it will serve a default page with links to exec, SDM, QDM and TAC support.
The ip http path flash: allows you the serve pages from the flash: device. Normally files cannot be served from flash: (other than home.html and home.shtml) unless you use the ip http path flash: command.
We now have our web server set up. Lets test it.
R1#telnet 10.0.23.3 80
Trying 10.0.23.3, 80 ... Open
get /index.html
<a href="http://www.ardenpackeer.com/picture.gif">picture.gif</a>
<a href="http://www.ardenpackeer.com/picture.jpg">picture.jpg</a>
[Connection to 10.0.23.3 closed by foreign host]
R1#copy http://10.0.23.3/index.html null0
Destination filename [null0]?
Erase flash: before copying? [confirm]n
Loading http://10.0.23.3/index.html
Verifying checksum... OK (0xA4BA)
174 bytes copied in 0.704 secs (247 bytes/sec)
You can see above, we telneted into R3 port 80, and issued a GET request which returned the html file we entered. We can also use the copy command to retrieve files from the web server on R3. Great Success!
We will be using this web server to test NBAR http protocol matching in another article, but for now we have a working web server in IOS under dynamips.
HTH! Now back to labs!
Summary:
Resources:
Webserver - Dynamips .net configuration file
Webserver - R1 Final Configuration
Webserver - R2 Final Configuration
Webserver - R3 Final Configuration
Webserver - Sample Webpage files
Discussion
No comments for “Tutorial: How to set up a Cisco router as a Web Server”
Post a comment