Question Locked

Edit Cisco ACL via Telnet?

0 helpful
27 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Having never done this before, I'm at a bit of a loss. I can login via telnet to our Cisco router (1721), enable it.. and look around at the access lists, but I can't seem to figure out how to do what I need to do.

I need to basically block all traffic on port 25 (smtp) unless it comes from our exchange server (lets say it's 192.168.1.112). I don't know any cisco commands really.. and sort of understand the different modes (sort of), but beyond that I don't know how to simply add in a few lines. What I have to do is this:

"First you need to create an access list describing the traffic (x.x.x.x is the ip address of the mail server)

access-list acl_out permit tcp host x.x.x.x any eq 25
access-list acl_out deny tcp any any eq 25
access-list acl_out permit ip any any

Then you need to apply that access-list to the inside interface(because it is being checked on the inside before it goes out)

access-group acl_out in interface inside"

How do I do that??

27 replies

by cypher.msix

Hey there. thanks for the reply. so I've created an access list # 102 and I'm not sure what interface to apply it to.

we have a single t1 that comes in and there's two ethernet ports hook up in the back of the router.

i did a 'show interface' or something like that and it lists an ethernet0 interface, fastethernet0 interface and a serial0 interface(which is down).

what im trying to do is block outgoing traffic on tcp port 25 unless it's from the mail server.. so what interface do i apply this to?

i was informed to use the command:

access-group 102 in interface inside

(but it doesn't work)because we want to stop the outbound traffic on the inside but i don't know how that translates to the router and it's interfaces. i've found i can do a:

config terminal
interface e0 (or f0, or s0)
ip access-group 102 out

and something happens, but how to i see the changes i've made? which interface do i apply this to?

i should clarify that the f0 interface has our internal ip address and the e0 interface has the external ip address...

by nimmo

So you have a T1 comming in on S0?, when you type show int s0 does it say "line down/line protocol down"? if so hop into interface configuration mode for s0 and type "no shut" to enable the interface.

A general rule about access lists is when you use a extended access list (100-199 or 2000 2699) you should place it as close to the Source as possible and when using a standard access list (1 - 99 or 1300 - 1999) place it as close to the destination as possible.

For example:

access-list 102 permit tcp host any eq 25
access-list 102 deny tcp any eq 25
access-list 102 permit ip any any
(implicit deny statement)

The ip access-group 102 out statement will go on the interface closest to the source of the traffic.

by cypher.msix

The T1 comes into either the ethernet0 or fastethernet0 .. direct or not i'm not sure .. but there are only two ethernet cables hooked up to the router.

when i do a 'show ip int' (where it lists the interfaces) it pops up with the ethernet0, fastethernet0, and serial0 interfaces. e0 and f0 are up, s0 is down, but i don't think we use the serial interface.

the access-list is just as you showed, and is created as extended access-list 102. just not sure where to bind it to as i don't quite understand how traffic flows from our network through the router as of yet.

what i do know is that e0 has an ip address of 64.x.x.x (which is the external ip assigned by the isp) and f0 has an internal ip address of 192.x.x.x (which is what we assigned). so knowing that, which is the "closest" to the inside?

do i want to bind group 102 to f0 out?

config t
int f0
ip access-group 102 out

?

another question.. this is the access-list that i have ready to go:

Extended IP access list 102
permit tcp host 192.168.1.112 any eq smtp
deny tcp any any eq smtp
permit ip any any

this says to me:

1) allow tcp traffic from on port 25

2) deny all tcp traffic on port 25

3) allow any tcp traffic over any other port

is that accurate? so basically no other machine on the network will be able to pass any packets on port 25 going out to the internet, but will be able to receive data coming from the internet into the network on port 25?

thanks for the help so far. my first time dealing with routers in this much detail. :)

by nimmo

What you want to do is to put the 102 access list on the outbound of e0 because that is your interface to the internet and you want to filter the traffic leaving your network heading to the internet.

yes access list 102 is saying.

1) Allow only your mail server to send smtp traffic out to the internet.
2) Deny any smtp traffic origionating from any other internal host to be sent out to the internet.
3) Allow all other traffic (ip traffic) to be sent to the internet.

Access lists flow top down so if you said deny tcp any any eq smtp no one will be able to send smtp traffic that is why you put the allow smtp for you mail server first.

As for internet traffic comming into the network, you dont have any access lists on the inbound of e0 so any traffic will be forwarded from the internet through the network.

Here is an article with should clarify ACL's better.

http://www.cisco.com/en/US/products/sw/secursw/ps1018/products_tech_note09186a00800a5b9a.shtml

http://www.cisco.com/en/US/docs/internetworking/technology/handbook/ito_doc.html

Take a look here aswell http://happyrouter.com/

by cypher.msix

First, just wanted to say thanks for all your help Nimmo. Hoping you'll be able to shed some light on this for me.

I have access-list 102 setup as follows:

RouterSR>show access-lists 102
Extended IP access list 102
permit tcp host 192.168.1.112 any eq smtp
deny tcp any any eq smtp (1059 matches)
permit ip any any (58988 matches)

I have that bound as follows:

RouterSR>show ip int e0
Ethernet0 is up, line protocol is up
Internet address is 64.xx.xx.xx/29
Broadcast address is 255.255.255.255
Address determined by non-volatile memory
MTU is 1500 bytes
Helper address is not set
Directed broadcast forwarding is disabled
Outgoing access list is 102
Inbound access list is not set
Proxy ARP is enabled
Local Proxy ARP is disabled
Security level is default
Split horizon is enabled
ICMP redirects are always sent
ICMP unreachables are always sent
ICMP mask replies are never sent
IP fast switching is enabled
IP fast switching on the same interface is disabled
IP Flow switching is enabled
IP CEF switching is disabled
IP Flow switching turbo vector
IP multicast fast switching is enabled
IP multicast distributed fast switching is disabled
IP route-cache flags are Fast, Flow
Router Discovery is disabled
IP output packet accounting is disabled
IP access violation accounting is disabled
TCP/IP header compression is disabled
RTP/IP header compression is disabled
Probe proxy name replies are disabled
Policy routing is disabled
Network address translation is enabled, interface in domain outside
WCCP Redirect outbound is disabled
WCCP Redirect inbound is disabled
WCCP Redirect exclude is disabled
BGP Policy Mapping is disabled

Having our router configured in this way does not allow us to send e-mail out to an external mail address.

I've even tried sending mail from the mailserver itself, and it's being blocked as well. Something isn't right here ... should that private ip address be the fqdm of the server? Should that matter? What am I missing?

by dumphrey

Because thats what you are blocking, not SMTP traffic, the SMTP is a "short cut" and a mnemonic.
permit tcp host 192.168.1.112 any eq smtp
and
permit tcp host 192.168.1.112 any eq 25
are identical. No idea why your mail server would not be on 25, but there it is...
Also, E0 is your wan interface? With your internet connection wired to it?

by netman1958

The order of operations for Cisco IOS is as follows:
Inside-to-Outside

(1)If IPSec then check input access list
(2)decryption - for CET (Cisco Encryption Technology) or IPSec
(3)check input access list
(4)check input rate limits
(5)input accounting
(6)policy routing
(7)routing
(8)redirect to web cache
(9)NAT inside to outside (local to global translation)
(10)crypto (check map and mark for encryption)
(11)check output access list
(12)inspect (Context-based Access Control (CBAC))
(13)TCP intercept
(14)encryption
(15)Queueing

As you can see, NAT occurs before applying the outbound access-list. So by the time the traffic reaches the access-list, the IP address has been translated from 192.168.1.112 to a public IP and does not match the access-list.

Normally, you would have any public servers "static NAT'ed" to one of the public IP's. I would need to see more of the configuration to determine if you have that set-up or not.

by cypher.msix

Interesting post, and I was curious if something like that was going on.

Our Exchange Server is private and as far as I know, doesn't have a static ip address from our ISP.. we just have the one reserved for our router. Since this is the case, how am I going to allow traffic from our mail server?

I could be wrong, as I'm picking up this job from someone who is already far and gone and trying to piece together this puzzle that is our network on my own. :)

by netman1958

Do you just need to be able to send email from this server or will it need to receive email too.

by cypher.msix

NetMan,

The mail server is our Exchange Server that all of our company computers use to send and receive e-mail. So to answer your question, yes it will need to receive e-mail as well.

Just to clarify, I'm assuming that the client machines send e-mail -through- the mail server, and not directly from the clients themselves (that just doesn't make any sense to me).

by cypher.msix

Yes, our internal mail server uses port 25 to send mail. :)

When I entered in the commands, I actually used 25 as the port number.. when I looked it up with the show ip int e0 command, it popped up with the smtp replacement which I thought was cutely annoying. :-P

by netman1958

In that case, to be sure I don't tell you something that would have unintended consequences, could you post the output of the "show run" command from your router? You can mask any usernames/passwords/Public IP addresses with asterisks. Then I will post the necessary changes.

by cypher.msix

Thanks for the help, NetMan. Appreciate it. :)

RouterSR#show run
Building configuration...

Current configuration : 4455 bytes
!
! No configuration change since last restart
!
version 12.2
service timestamps debug datetime localtime
service timestamps log datetime localtime
no service password-encryption
!
hostname RouterSR
!
boot system flash c1700-k9o3sy7-mz.122-11.T8.bin
aaa new-model
!
!
aaa authentication login userauthen group radius
aaa authorization network groupauthor local
aaa session-id common
enable secret 5 [secret]
enable password [password]
!
username [login] password 0 [password]
username [login] privilege 15 password 0 [password]
clock timezone PST -8
clock summer-time PST recurring 2 Sun Mar 2:00 1 Sun Nov 2:00
ip subnet-zero
!
!
!
ip audit notify log
ip audit po max-events 100
!
!
crypto isakmp policy 3
authentication pre-share
group 2
!
crypto isakmp policy 5
hash md5
authentication pre-share
group 2
crypto isakmp keepalive 10
!
crypto isakmp client configuration group [group]
key [password]
wins 192.168.1.112
pool ippool
!
!
crypto ipsec transform-set myset esp-des esp-md5-hmac
!
crypto dynamic-map dynmap 10
set transform-set myset
!
!
crypto map clientmap client authentication list userauthen
crypto map clientmap isakmp authorization list groupauthor
crypto map clientmap client configuration address respond
crypto map clientmap 10 ipsec-isakmp dynamic dynmap
!
!
!
!
interface Ethernet0
ip address 64.00.00.00 255.255.255.248
ip nat outside
ip route-cache flow
half-duplex
crypto map clientmap
!
interface FastEthernet0
ip address 192.168.2.1 255.255.255.0 secondary
ip address 192.168.1.254 255.255.255.0
ip access-group 101 in
ip nat inside
ip route-cache flow
speed auto
full-duplex
!
interface Serial0
ip address 192.168.3.20 255.255.255.0
ip nat inside
encapsulation ppp
ip route-cache flow
fair-queue
service-module t1 clock source internal
service-module t1 timeslots 1-24
!
router rip
network 192.168.1.0
network 192.168.2.0
!
ip local pool ippool 192.168.5.1 192.168.5.254
ip nat pool ovrld 64.00.00.00 64.00.00.00 prefix-length 24
ip nat inside source list 117 pool ovrld overload
ip nat inside source static tcp 192.168.1.6 80 64.00.00.00 80 extendable
ip nat inside source static tcp 192.168.1.9 8234 64.00.00.00 8234 extendable
ip nat inside source static tcp 192.168.1.112 443 64.00.00.00 443 extendable
ip nat inside source static tcp 192.168.1.112 25 64.00.00.00 25 extendable
ip nat inside source static tcp 192.168.1.112 143 64.00.00.00 143 extendable
ip nat inside source static tcp 192.168.1.110 21 64.00.00.00 21 extendable
ip nat inside source static tcp 192.168.1.251 1024 64.00.00.00 1024 extendable
ip nat inside source static tcp 192.168.1.106 1800 64.00.00.00 1800 extendable
ip nat inside source static tcp 192.168.1.7 5900 64.00.00.00 5900 extendable
ip classless
ip route 0.0.0.0 0.0.0.0 64.00.00.89
ip http server
!
!
ip access-list extended addr-pool
ip access-list extended archive
ip access-list extended configure
ip access-list extended console
ip access-list extended dns-servers
ip access-list extended exec
ip access-list extended idletime
ip access-list extended inacl
ip access-list extended key-exchange
ip access-list extended level
ip access-list extended protocol
ip access-list extended service
ip access-list extended timeout
ip access-list extended tunnel-password
ip access-list extended wins-servers
!
logging trap debugging
logging 192.168.1.107
access-list 101 permit tcp any any eq www log
access-list 101 permit ip any any
access-list 102 permit tcp host 192.168.1.112 any eq smtp
access-list 102 deny tcp any any eq smtp
access-list 102 permit ip any any
access-list 115 deny tcp any any eq 5050
access-list 115 deny tcp any any eq 1863
access-list 115 deny tcp any any eq 5190
access-list 115 deny tcp any any eq 7000
access-list 115 deny tcp any any eq 6660
access-list 117 deny ip 192.168.1.0 0.0.0.255 192.168.5.0 0.0.0.255
access-list 117 permit ip 192.168.1.0 0.0.0.255 any
access-list 117 permit ip 192.168.2.0 0.0.0.255 any
access-list 117 permit ip 192.168.3.0 0.0.0.255 any
!
snmp-server community P1ub2lic RO
snmp-server enable traps tty
radius-server host 192.168.1.112 auth-port 1645 acct-port 1646 key [password]
radius-server host 192.168.1.110 auth-port 1645 acct-port 1646 key [password]
radius-server retransmit 3
radius-server authorization permit missing Service-Type
!
line con 0
line aux 0
line vty 0 4
password [password]
line vty 5 6
!
ntp authenticate
ntp clock-period 17179980
ntp server 209.81.9.7
end

by netman1958

Let's try a little test to make sure I'm on the right track.
Open a command prompt on your email server and enter the following:
telnet 209.191.118.103 25
[ENTER]
If it connects you will see this:
220 mta505.mail.mud.yahoo.com ESMTP YSmtp service ready
If it doesn't connect you will see an error message.
If it doesn't connect, login to your router and type the same command i.e.
telnet 209.191.118.103 25
[ENTER]
and let me know the results of both tests.

Thanks,
Netman

by cypher.msix

NetMan

I was able to successfully telnet to that ip from the command prompt, and decided to try it out through the router just in case it might be important to know. Here were the results:

RouterSR>telnet 209.191.118.103 25
Trying 209.191.118.103, 25 ... Open

[Connection to 209.191.118.103 closed by foreign host]
RouterSR>

by netman1958

Results
NetMan

I was able to successfully telnet to that ip from the command prompt, and decided to try it out through the router just in case it might be important to know. Here were the results:

RouterSR>telnet 209.191.118.103 25
Trying 209.191.118.103, 25 ... Open

[Connection to 209.191.118.103 closed by foreign host]
RouterSR>

OK, now we're getting somewhere. If you can telnet from your email server to another email server's port 25 and it answers, then the smtp traffic is passing through the router OK. Has this email server been working previously? If so, has anything been changed on the server or the Exchange config?
When you try to send email does it bounce or stack up in the queue on the server? If it bounces, can you post the error message?

We've got her on the run now!

by cypher.msix

OK, now we're getting somewhere. If you can telnet from your email server to another email server's port 25 and it answers, then the smtp traffic is passing through the router OK. Has this email server been working previously? If so, has anything been changed on the server or the Exchange config?
When you try to send email does it bounce or stack up in the queue on the server? If it bounces, can you post the error message?

We've got her on the run now!

---------

NetMan,

You know, I looked at my monitors today and realized I have twelve remote desktop sessions open.. and it got me to wondering if I ran those telnet commands from the right server. Turns out, I did not. I ran it from one of the clients :-/

In fact, it seems there is a problem trying to open a telnet session to the yahoo mail servers as shown below:

direct fromm mail server:

421 Message from (64.00.00.00) temporarily deferred - 4.16.50. Please refer to h
ttp://help.yahoo.com/help/us/mail/defer/defer-06.html

Connection to host lost.

U:\>

through router:

RouterSR>telnet 209.191.118.103 25
Trying 209.191.118.103, 25 ... Open
421 Message from (64.00.00.00) temporarily deferred - 4.16.50. Please refer to h
ttp://help.yahoo.com/help/us/mail/defer/defer-06.html

[Connection to 209.191.118.103 closed by foreign host]
RouterSR>

To answer your questions and shed more light on the current situation, the mail server has been up and running for years before I came along. We're recently been running into a lot of spyware problems for various reasons, and have been blacklisted multiple times already. One of the things that I want to accomplish is to help prevent that from happening in the future is to prevent any client or server from sending traffic out to the internet through port 25, hopefully stopping a few naughty malware apps from e-mail itself (with the exception of the mail server, of course).

So, I wrote an ACL to handle that task (extended acl 102) and applied it to the outbound ethernet0 tunnel thing... whatever it's called... and unfortunately it seems that everything got blocked on port 25, even the mail server. As I can't have the entire office not able to send e-mail out, I had to remove the acl and that's where we're at right now.

When I did have the acl in effect, I noticed that while no e-mails would be sent, as soon as I re-booted the router (essentially refreshing the config to it's previous state) the e-mails I tried to send through finally went indicating that they were stacking up waiting to go through.

Thanks for all your help so far. It's beyond apreciated! :-)

by netman1958

OK, your answer confirmed what I was suspecting. This error message:
"421 Message from (64.00.00.00) temporarily deferred - 4.16.50. Please refer to h
ttp://help.yahoo.com/help/us/mail/defer/defer-06.html"
actually came from the yahoo server, so that confirms that the router is not blocking your SMTP traffic. That message indicates that your IP address(s) are being refused by yahoo (and probably others) due to an abuse policy.

First, let's take care of configuring your router to do what you want it to.
connect to your router and type the following:

conf t
interface FastEthernet0
no ip access-group 101 in
ip access-group 102 in

after you enter those commands press and hold the ctrl key and press the "Z" key.

Now type the following:
wr mem

Now run the telnet test again from the server:
telnet 209.191.118.103 25
and you should get the same message you got before.

Then try the telnet test from another computer on the network and it shouldn't ever connect to the yahoo server.

Let me know the results and we will go from there.

Netman

by cypher.msix

Applied the acl as you instructed and was able to get out from our mail server to the yahoo mail server. Trying to do the same from one of our clients resulted in a failed connection.

from the mail server:

421 Message from (64.00.00.00) temporarily deferred - 4.16.50. Please refer to h
ttp://help.yahoo.com/help/us/mail/defer/defer-06.html

Connection to host lost.

from the client:

U:\>telnet 209.191.118.103 25
Connecting To 209.191.118.103...Could not open connection to the host, on port 25: Connect failed

That's good news! So, I guess I ended up applying the ACL to the wrong thing.. so then which line does the T1 come in on? The Ethernet0 or the FastEthernet0? And why are we applying the ACL to the "in" rather than the "out"? Is it because "in" means going "coming from the inside going outside" rather than "coming inside from the outside"?

Granted, I've learned quite a bit about all this cisco router jargon, but it's still rather confusing. I think if I understood more about what the f0 and the e0 is and what the 'in' and 'out' on each of those meant, I would be in better shape for the future. :-)

by bhymen

The trick to the application of access-lists is to view the traffic from the router's perspective. Traffic originating on your local network(LAN) and destined for another subnet(such as the internet) first has to enter the router on it's LAN interface(in your case FastEthernet0). In other words it has to come IN on FastEthernet0. Then it has to go OUT on a different interface(in your case Ethernet0).
When the remote computer answers your traffic it first has to come IN on Ethernet0 and then OUT of FastEthernet0 to reach the computer on the LAN that originated the conversation.

In between coming in one interface and out another, the packets are processed by the router based on it's configuration and that's where the order of operations I posted earlier come into play. When you had the access-list 102 applied to Ethernet0 outbound, the outbound packets had already come IN on FastEthernet0 and been processed. One of those processes was NAT which happened before the access-list was consulted. NAT translated the IP Address from 192.168.1.112 to 64.00.00.XX. Next it got compared to access-list 102 from top to bottom. So:
(1)access-list 102 permit tcp host 192.168.1.112 any eq smtp - no match because it's ip address has already been translated to 64.00.00.XX
(2)access-list 102 deny tcp any any eq smtp - matches since any includes 64.00.00.XX.
And it drops the packet.

Your interface Serial0 is configured for a T1, however I believe you said nothing was connected to that port. So my bet is that your T1 terminates at an IAD(integarted access device) such as an AdTran which then connects to your router via Ethernet on router interface FastEthernet0. Possibly you can trace the cable from your routers FastEthernet0 and find out where it goes.

I see some additional things you might want to do regarding the router config. If you want to communicate outside the forum, let me know and we will talk offline.

Netman

Edit: After I submitted this, I realized my co-worker (bhymen) was logged on and it submitted under his name. Sorry about that. Netman

by cypher.msix

NetMan,

Thanks for helping me understand how all of that works. After drawing out a visual diagram of your description I am finally able to understand the interfaces and how the router interpets where data is coming in and going out. Makes a whole lot more sense now! :-)

What sort of additional changes would you suggest making? I'm all for cleaning up and optimizing as much as possible. I'll send you a private message with my e-mail address.

*edit* It seems that I can't send you a private message, so maybe you can p.m. me and we can talk offline about the router. Thanks *edit*

by netman1958

That's wierd, I just checked my profile and it's set to allow other members to contact me. I am also unable to PM you. Is your profile set to allow member contact? Maybe both have to be enabled. Check your profile and let me know.

by netman1958

See reply above posted under bymen. I didn't realize he was logged on at my computer when I posted my reply. I'm sending him back to Huntsville!

by cypher.msix

Mine was set to disallow, but that has been changed. I still can't send a private message to you for some reason. If you still can't private message me, I can post a junk e-mail account that you can e-mail to, and we'll continue with our regular accounts from there.

by netman1958

That's very strange, I still can't send you a PM, you still can't send me a PM but I can send another member a PM. Don't know what's going on with that. Anyway, here's a yahoo.com email that I never use:
netman1958 at

send an email to that address with your real email address and I will contact you from my real email address and we will take it from there.

Cheers,
Netman

This discussion is closed to new replies.