route 설정시 class A/B/C 판별하는 방법이 있을까요?

dorado2의 이미지

DHCP server에서 static route 옵션으로 여러 route를 넘겨줄 수 있다고 할 때요.
이 값들을 route 명령으로 설정해주려고 하고 있습니다.

기존에는

route add -net $(destination) netmask 255.255.255.0 gw $(route) dev eth0 

이런 동일한 명령으로 설정해주었더니, host인 경우나 class A,B인 경우에 제대로 설정이 되지 않네요.

아래가 실제 주어지는 route 정보이고요.

   destination      route       
1. 192.168.2.1    192.1.5.1(class C)  
2. 192.168.0.1    192.1.5.1(class C)  
3. 192.168.1.0    192.1.5.1(class C)  
4. 172.16.1.0     192.1.5.1(class B)  
5. 10.1.3.0       192.1.5.1(class A)  

아래가 설정된 값을 route 명령으로 확인해본 것입니다. 3번만 OK이고 4,5번은 netmask를 잘못 넣었고,
1,2번은 설정 파라미터에 잘못이 있어서 설정이 되지 않았습니다.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     192.1.5.1       255.255.255.0   UG    0      0        0 eth0      --> 3번 OK 
172.16.1.0      192.1.5.1       255.255.255.0   UG    0      0        0 eth0      --> 4번 Netmask 잘못됨 
197.1.5.0       *               255.255.255.0   U     0      0        0 eth0     
10.1.3.0        192.1.5.1       255.255.255.0   UG    0      0        0 eth0      --> 5번 Netmask 잘못됨
default         192.1.5.1       0.0.0.0         UG    0      0        0 eth0

1,2 번은 destination이 host이니까
route add -host 192.168.2.1 gw 192.1.5.1 dev eth0 처럼 설정이 되야 될 것 같구요.

4,5번은 class C가 아닌 class A,B 주소라 netmask를 각각 255.255.0.0, 255.0.0.0 로 넣어줘야 할 것 같은데요,

스크립트 상에서 ip주소를 보고 class A,B,C를 구분하는 방법이 있을까요?
그리고 destination이 host인 경우 이를 구분할 방법이 있을까요? ip 4가지 숫자 중 마지막이 0이 아님을 체크하면 될 것 같긴 한데요.

현재 destination IP와 route IP는 dhcp client로부터 각각 하나의 string 형태로 전달되서 스크립트에서 사용하는 상태입니다.

dorado2의 이미지


구글신이 알려주네요. 검색어 바꾸며 겨우 찾았습니다.

http://jodies.de/ipcalc 에서 perl script 제공합니다.

bash shell script 잘 몰라서 바꾸는데 시간이 좀 걸렸지만,
위 사이트 내용 참고하심 될 듯 하네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.