I want to setup a dynamic routing network， I want to know, What is the difference between BGP and OSPF ? Does both two need to be used together commonly ?
Based on your question, I'm guessing that you are new to networking and just require a high-level answer.
- BGP (Border Gateway Protocol) is used at the edge of your network to connect your network to the Internet
- OSPF (Open Shortest Path First) is used internally inside your network
At the edge of your network, you would use routers to map BGP to OSPF and vice-versa.
Routing is not a simple topic - you should plan to spend a lot of time studying and designing your solution. There are also other protocols available such as RIP, IS-IS and IGRP which may be more suitable for your requirements.
If you are doing internal routing, i.e. routing within a site, company, or campus, you will want to use OSPF. Typically BGP is needed at a site edge, where you route out to the public internet. In small and medium size networks, static routes to the outside will usually be preferable to setting up BGP. If you have a complicated multi-homed site, regardless of size, you might consider BGP.
You really won't want to use IGRP -- it's the deprecated, older verson of Cisco's proprietary EIGRP (also proprietary). EIGRP is reliable, fairly intuitive, and comparable in performance to OSPF, but runs only on Cisco equipment.
I would not recommend IS-IS for most projects. IS-IS is a link-state protocol like OSPF, but is used rarely, typically only at ISP's these days (though some would call it a widespread, but niche, routing protocol). You can certainly use it if it's available on your platform, but you will find troubleshooting resources harder to come by.
RIP is adequate for and most suitable for a small site, though you on Linux (and most modern platforms), you'll actually be using RIPv2. It is easier to set up than the others mentioned, though it isn't used outside of small network deployments any more because of its limitations. If you're trying to gain knowledge, it makes a good starting point.
OSPF is the vendor-neutral IGP standard (i.e., not Cisco-proprietary), and can be easy to complex, depending on your needs.
I'm assuming you are talking about IPv4 instead of IPv6. Your requirements in this respect (as in others) will have a direct bearing on what routing protocol you use. OSPFv3 is the IPv6 capable version of OSPF ; OSPFv2 is the most common now, but is IPv4 only.
*nix-wise, bsd systems are also good choices for running production-level bsd or ospf deployments, if the hardware can handle the throughput.
You do realise that to use IBGP you must create peering relationships between edge routers, and for those edge routers to be able to establish that peering they must also run an IGP such as OSPF, RIP or ISIS. No one runs IBGP on it's own without a proper IGP. IBGP typically only runs on the edge routers and any route reflectors in an AS...not on all the routers, whereas OSPF and the like run on all routers.
I've never seen a network that only runs IBGP. In fact it is virtually impossible since BGP relies on the existing underlying routing table to figure out how to route to the next IBGP peer. The only time it is really used is if a single autonomous system is connected to other ASs by more than one link. For example one router in AS 100 peers with one ISP and another router, also in AS 100, peers with a backup or second ISP. In this case, IBGP is used between those 2 routers. Outside this scenario IBGP should not be used.
For the record IBGP exchanges much more information than OSPF meaning there is more overhead. Also it typically cannot converge as quick since it sits a level above an IGP on the protocol stack.
IGPs are routing protocols (i.e. OSPF, ISIS, EIGRP, RIP).
BGP is a topology protocol that was extended for multihoming scenarios. The "I" in IBGP does not imply it is an IGP.
Based on the tags on your question - are you interested in having your ubuntu-server acting as a router? If this is the case, Ubuntu does appear to have a port of the OSPF protocol in the nemesis-ospf project. For BGP the Vyatta distro (how-to) would be the best choice and can also do OSPF (both are not necessary btw) as well as DNS, DHCP and other services.
More generally, OSPF is going to be a much simpler routing protocol to setup, configure and understand quickly. BGP is much more involved and is likely overkill for a small simple network. OSPF is considered a link-state protocol while BGP is path-vector. The links above will go into much greater detail, but my suggestion is to look into OSPF.
I would, however, suggest using a dedicated box to do your routing and not run it on a box doing other services unless this is only for educational/learning/lab purposes only.
ospf is internal gateway ,whereas bgp is external gateway.
convergence fast in ospf , slow in bgp.
design - hierarchical network possible in ospf , fully meshed in bgp.
Algorithm - ospf uses Dijkstra Algorithm , bgp uses best path algorithm.
Protocol - ospf has IP protocol , bgp has TCP protocol.
Port - ospf has port 89 , bgp has port 179.
type - Link state in ospf , Path vector in bgp.
Need of device resources - Memory & CPU intensive in ospf , Depends on the size of the routing table but scales better than ospf.